I have JavaScript that outputs links (search results) but I’m having problems adding onclick in the anchor tag
var str = "<a href='#bokvisning' onclick='javascript:$(#bokvisning_content).load('http://www.akademika.no/node/"+item.link+"')'>" + item.title + "</a>";
It outputs this, which is wrong:
<a href="#bokvisning" onclick="javascript:$(#bokvisning_content).load(" http:="" www.akademika.no="" node="" link')'="">Title</a>`
Is it possible? What other options do I have?
The quick fix is the quotes, like this:
It would be better to add the click handler unobtrusively though, like this:
Then append that to whatever element you’re currently putting the string in.
Note: The second option above assumes jQuery is an option because your
onclickis using it.