I have a link:
<ul id="titleee" class="gallery">
<li>
<a href="#inline" rel="prettyPhoto">Talent</a>
</li>
</ul>
and I am trying to trigger it by using:
$(document).ready(function() {
$('#titleee').find('a').trigger('click');
});
But it doesn't work.
I've also tried: $('#titleee a').trigger('click');
Edit:
I actually need to trigger whatever get's called here <a href="#inline" rel="prettyPhoto">
This is the demo how to trigger event
For links this should work:
You should call the element's native .click() method or use the createEvent API.
For more info, please visit: https://learn.jquery.com/events/triggering-event-handlers/
Well you have to setup the click event first then you can trigger it and see what happens:
With the code you provided, you cannot expect anything to happen. I second @mashappslabs : first add an event handler :
then trigger your event :
and you should see the message in your console.
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:
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:
No need to call find. :)