I am using jquery to append content to my html. In the onclick function, I want to send a javascript variable to a function but it is not working.
Here is the code:
var link = "some url"; $('#header').append('<a onclick="activateLink(link);">Click</a>'); function activateLink(vlink) { window.open(vlink, '_blank'); } I have tried the following
$('#header').append('<a onclick="activeLink**("'+link+'")**;">Click</a>'); AND
$('#header').append('<a onclick="activeLink**('+link+')**;">Click</a>'); nothing seems to work. any help is appreciated.
linka local variable? Inline Javascript can only access global variables.