开发者

How to fire existing "onclick" event on a "a href" element using JQuery?

开发者 https://www.devze.com 2023-01-12 02:24 出处:网络
So the page is broken down some sections and each section has a \'a\' tag.When clicking on thelink it fires the \'on开发者_如何学Goclick\' event which calls a javascript function.

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();
0

精彩评论

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