I know this question has been asked before, but after a search on the web I can't seem to find a straight forward answer.
the HTML
<a id=myAnchor href=index.php>
the jQuery (Both of these do not work)
$('#myAnchor').click();
or
$('#myAnchor').trigger('click');
What is the simplest and most efficient way to achieve this?
$( "#foo" ). trigger( "click" ); As of jQuery 1.3, . trigger() ed events bubble up the DOM tree; an event handler can stop the bubbling by returning false from the handler or calling the .
jQuery trigger() Method The trigger() method triggers the specified event and the default behavior of an event (like form submission) for the selected elements. This method is similar to the triggerHandler() method, except that triggerHandler() does not trigger the default behavior of the event.
Try this:
$('#myAnchor')[0].click();
It works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With