views:

66

answers:

3

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.

A: 
$(element).click();

Should work.

See: http://docs.jquery.com/Events/click

Quintin Robinson
+2  A: 
$("myelement").click();

or

$("myelement").trigger("click");

Second is useful if you need to decide event type in runtime.

Alex Lebedev
+2  A: 

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');
James Skidmore
It's not working..it's working only if I click the link, doesn't do it automatically
Uffo
Check out the edit I made above.
James Skidmore