Reputation: 10046
I have an element, an anchor, how can I "click it" with jQuery, I mean like a normal user click, because I'm receiving a click on an element..but also I need to fire more events...
Ok here is my example
<a class="som" href="http://domain.com/ssl-signup.php" target="_blank">Test Link</a>
$(document).ready(function(){
$('.som').click();
});
But nothing happens!
Best Regards.
Upvotes: 0
Views: 2478
Reputation: 6044
$("myelement").click();
or
$("myelement").trigger("click");
Second is useful if you need to decide event type in runtime.
Upvotes: 4
Reputation: 50288
Firing the click
action for an anchor will not redirect the user to the anchor's URL as you would expect with a normal click
.
Instead, you'll need to do this:
$('#anchorId').click(function(){
window.location.href = $(this).attr('href');
});
EDIT -- CORRECT ANSWER BELOW
I misunderstood the question. To accomplish what you want, just make this call to simulate the click
:
window.location.href = $('#anchorId').attr('href');
Upvotes: 2
Reputation: 82325
$(element).click();
Should work.
See: http://docs.jquery.com/Events/click
Upvotes: 0