开发者

jQuery element click

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.


$("myelement").click();

or

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

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


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


$(element).click();

Should work.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜