I am trying to trigger click event on hyperlink with jQuery like the way below. Hyperlink does not have any id but it does have cssclass
$(document).ready(function () { $('.cssbuttongo').trigger('click'); });
The function above is not working. This is the hyperlink
<a href="hyperlinkurl" class="cssbuttongo">hyperlink anchor</a>
The native DOM method does the right thing:
$('.cssbuttongo')[0].click();
^
Important!
This works regardless of whether the href
is a URL, a fragment (e.g. #blah
) or even a javascript:
.
Note that this calls the DOM click
method instead of the jQuery click
method (which is very incomplete and completely ignores href
).