Reputation: 57196
How can I use trigger()
to trigger the click event on a particular link only?
for instance, I have this menu,
<li><a href="#" class="load-popup-public 500x400">1</a></li>
<li><a href="#" class="load-popup-public 500x400">2</a></li>
<li><a href="#" class="load-popup-public 500x400">3</a></li>
<li><a href="#" class="load-popup-public 500x400">4</a></li>
and I want to trigger the first link only when the page is loaded. so that I can call this function automatically when the page is loaded,
$('.load-popup-public').click(function (){
...
});
Upvotes: 0
Views: 1316
Reputation: 82913
You can use :first
selector to select the first link and then use document ready
event.
Try this:
$(function(){
$('.load-popup-public').click(function (){
//Some code here
});
$(".load-popup-public:first").trigger("click");
})
Working example: http://jsfiddle.net/zeyWN/
Upvotes: 1