jquery trigger: how can I use it to trigger a link when the page is loaded -


how can use trigger() trigger click event on particular link only?

for instance, have 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 want trigger first link when page loaded. can call function automatically when page loaded,

$('.load-popup-public').click(function (){ ... }); 

you can use :first selector select first link , 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/


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -