Putting hyperlinks on Google sites using jQuery
-
07-07-2021 - |
Domanda
I am trying to put a text (containing a hyperlink) using the click function in jQuery.
var publicationsText = "Rohit. <a href=\"http://www.google.com\" onmouseover=\"this.style.color=#EC4D48;\" onmouseout=\"this.style.color=#666;\" style=\"color:#666;\">Emerging Energy</a>";
$('#publicationsID').click(function(){
$("#homepage").html(publicationsText);
return false;
});
This works fine as intended on my local box. But when I publish this on Google sites, the HTML produced is:
<div id="container-caja-guest-0___">
<div id="homepage-caja-guest-0___">
Rohit.<a target="_blank" style="color: #666">Emerging Energy</a>
</div>
</div>
And the hyperlink is automatically removed.
Can any one please suggest a workaround that works on the Google sites?
Moreover the site is available at: http://www.wattalyst.org (and you can see the problem in Contact/Publications page)
Thanks!
Soluzione
Your string is incorrectly formatted. You need to escape the quotes and merge the lines
var publicationsText = "Rohit. <a href=\"http://www.google.com\" "+
" onmouseover=\"this.style.color=#EC4D48;\" onmouseout=\"this.style.color=#666;\" "+
" style=\"color:#666;\">Emerging Energy</a>";
Altri suggerimenti
You're building your HTML
string incorrectly (not escaping double quotes):
var publicationsText = "Rohit. <a href=\"http://www.google.com\"" +
"onmouseover=\"this.style.color=#EC4D48;\"" +
"onmouseout=\"this.style.color=#666;\"" +
"style=\"color:#666;\">Emerging Energy</a>";
You don't have escaping of double quotes in href
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow