How to fire existing "onclick" event on a "a href" element using JQuery?
So the page is broken down some sections and each section has a 'a' tag. When clicking on the link it fires the 'on开发者_如何学Goclick' event which calls a javascript function.
I am adding a link at the top of the page that when you click on the link it will call a JQuery function .click that will call all the 'a' tag 'onclick' events.
Is this possible?
The other coveat is that in the 'onclick' event, the function that is called is passing the ID of the parent DIV id. So I really need to fire the 'onclick' event and not call the javascript function directly within the JQuery function.
You can use .click()
directly, like this:
$("a.selector").click();
Give it a try here, though it's a jQuery function, it'll call the in-line bound click handlers as well.
use trigger():
$("a#mylink").trigger("click");
Or the shortcut, click():
$("a#mylink").click();
精彩评论