0

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.

3 Answers 3

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

or

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

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

Sign up to request clarification or add additional context in comments.

Comments

2

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');

1 Comment

It's not working..it's working only if I click the link, doesn't do it automatically
0
$(element).click();

Should work.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.