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')
精彩评论