I'm writing a chrome extension, and I'm trying to add a link that calls a javascript function, exactly like in the question.
However, when I click the link, nothing happens - and when I look at the debug console, the "a" node doesn't have an "onclick" property at all, it just looks like this:
<a href="#">Add to likes</a>
This is my code:
function generateEntry(innerEntry) {
var a = document.createElement('a');
var linkText = document.createTextNode("Add to likes");
a.appendChild(linkText);
a.onclick="addToLikes('" + "hello" + "')"
a.href = "#";
return a
}
If I manually add the "onclick" declaration in the debug console, everything works.
<a href="#" onclick="addToLikes('hello2')">Add to my likes</a>
What's wrong with my script?