JQuery: trigger () will not work with reference

I am trying to trigger() link, but it does not work.

The <img> element has a rel attribute that contains the link identifier. When you click on an item, activate the corresponding link, if possible.

I think the problem is that I am capturing a jQuery click event, not a native link action.

Anyway, here is the code for you:

 $("#contentmenu li a").click(function(e){ switch(e.target.id){ case "opt1": alert('do something'); break; case "opt2": alert('do something'); break; case "opt3": alert('do something'); break; } //return false; }); $("#box_content img").click(function(e){ menuItem=$(this).attr('rel'); $('#'+menuItem).trigger('click'); //return false; }); 

EDIT

I found my answer: it is not possible to trigger a native link event this way so I will resort to using window.location .

+4
source share
1 answer
 $('#YourLinkId')[0].click(); 

I tested IE9, IE8 and Chrome. This works in IE but does not work in Chrome!

+1
source

All Articles