开发者

How to programmatically trigger the click on a link using jQuery?

How to programmatically trigger the clic开发者_如何转开发k on a link using jQuery?


$('#your_link_id').click()

See the excellent jquery docs for more information


If you have an anchor link:

<a id="my_link_id" href="something">My Link</a>

it will fail as other answers have mentioned. Calling .eq and .trigger('click') doesn't work for me, but this does:

$('#your_link_id').get(0).click();

In my specific case, I've assigned a blob url programmatically to the anchor's href.


You can use trigger:

$('#your_link_id').trigger('click');


$('#your_link_id').eq(0).trigger('click');

or you can use $('#your_link_id')[0].trigger('click');

is needed as jQuery returns an array and we cannot trigger click on multiple eventlinks. You have to target only a single element

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜