Jquery how to trigger click event on href element

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>

Thanks for the answers.


In addition to romkyns’s great answer.. here is some relevant documentation/examples.

DOM Elements have a native .click() method.

The HTMLElement.click() method simulates a mouse click on an element.

When click is used, it also fires the element’s click event which will bubble up to elements higher up the document tree (or event chain) and fire their click events too. However, bubbling of a click event will not cause an <a> element to initiate navigation as if a real mouse-click had been received. (mdn reference)

Relevant W3 documentation.

A few examples..


You can access a specific DOM element from a jQuery object: (example)



You can use the .get() method to retrieve a DOM element from a jQuery object: (example)



As expected, you can select the DOM element and call the .click() method. (example)


It’s worth pointing out that jQuery is not required to trigger a native .click() event.