开发者

Trigger OnClick in anchor tag

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜