Search code examples
jqueryclickawesomium

How do I trigger the onclick event handler in an anchor tag using jquery


I have an anchor tag with an onlick attribute containing some javascript code. I need to get this javascript executed using jquery or javascript. I have tried to call the click event on the anchor tag element but nothing happens. Clicking the anchor tag manually on the site works just fine but I cannot get it to work thru jquery.

/Måns


Solution

  • Without example code I don't see any reason why something like this wouldn't work:

    $('#some-link').click();
    

    A possibly unsafe alternative would be...

    var oc = $('#some-link').attr('onclick');
    eval(oc);