开发者

Trigger OnClick in anchor tag

开发者 https://www.devze.com 2023-03-07 05:13 出处:网络
How can i use trigger() in jquery to emulate onclick attribute of a anchor tag: <a id=\"anc\" href=\"#\" onclick=\"someFunction()\"> some text </a>

How can i use trigger() in jquery to emulate onclick attribute of a anchor tag:

<a id="anc" href="#" onclick="someFunction()"> some text </a>

here if i use 开发者_JAVA百科

$("anc").trigger('click');

its not working


you need to correctly reference the id "anc" in the jQuery selector with a #:

$("#anc").trigger('click');


you need to use # for id

$("#anc").click(function() {
    return false // this will kill the default behaviour and your page won't jump
});


when using an id you can use ('#idname').trigger('click') , when using a class you can use ('.classname').trigger)('click')

0

精彩评论

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