Skip to content Skip to sidebar Skip to footer

Jquery Click() On A Link

I'm trying to trigger a click on a link when a page loads via ajax call, I tried all methods I found, but I can't manage to do that. Considering that the link on which I want to tr

Solution 1:

EDIT, I think this is what you're looking for:

html:

<a href="http://www.google.com" target="_blank"id="cliccami">Click here</a>

jQuery:

$(document).ready(function() {

    $('#cliccami').click(function(e) {
        window.open($(this).attr('href'));
        e.preventDefault();
    });

    $('#cliccami').click();
});

In my example (JSFiddle: http://jsfiddle.net/qw9BW/) #cliccami's click event is captured, alerted, then stopped. then a $.click() is ran on page load to force the click event to happen.

Solution 2:

Have you tried using a ready function?

$(document).ready(function() {
   $("#cliccami").trigger("click");
});

Post a Comment for "Jquery Click() On A Link"