Patrioticcow Patrioticcow - 1 year ago 208
jQuery Question

How to trigger a click on a link using jQuery

I have a link:

<ul id="titleee" class="gallery">
<a href="#inline" rel="prettyPhoto">Talent</a>

and I am trying to trigger it by using:

$(document).ready(function() {

But it doesn't work.

I've also tried:
$('#titleee a').trigger('click');


I actually need to trigger whatever get's called here
<a href="#inline" rel="prettyPhoto">

Answer Source

If you are trying to trigger an event on the anchor, then the code you have will work I recreated your example in jsfiddle with an added eventHandler so you can see that it works:

$(document).on("click", "a", function(){
    $(this).text("It works!");


Are you trying to cause the user to navigate to a certain point on the webpage by clicking the anchor, or are you trying to trigger events bound to it? Maybe you haven't actually bound the click event successfully to the event?

Also this:


is the equivalent of this:

$('#titleee a').trigger('click');

No need to call find. :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download