How to programmatically trigger a click on a link using jquery?

How to programmatically trigger a click on a link using jquery?

+49
jquery
May 17 '10 at 7:06
source share
4 answers
$('#your_link_id').click() 

See the excellent jquery docs for more information.

+43
May 17 '10 at 7:08 a.m.
source share

If you have an anchor link:

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

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

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

In my particular case, I assigned the blob url programmatically to the href binding.

+26
Apr 16 '14 at 1:11
source share

You can use trigger :

 $('#your_link_id').trigger('click'); 
+19
May 17 '10 at 7:10
source share
 $('#your_link_id')[0].trigger('click'); 

required because jQuery returns an array and we cannot trigger a click on multiple eventlinks. You must target only one item

+15
Mar 18 '13 at 14:06
source share



All Articles