I am trying to trigger a click on the first child .loader
when the document is ready, but without success:
HTML:
<a class="loader" data-target="david-boy" title="Danny Boy-Rivera"> <span class="img"><span class="play"></span><img src="img/gallery-image1.jpg" alt="" /></span> <h2>Danny Boy</h2> </a>
JQuery
//Does not work $('a.loader:first-child').bind('click'); $('a.loader:first-child').trigger('click'); $('a.loader:first-child').click(); //Works $('a.loader:first-child').css("background", "red");
Any ideas why?
Update
Handler:
$('.loader').click(function(){ var name=$(this).data("target"); callVideo(name); });
Update2
So the problem was that I declared the :first-child
action before the handler. I changed their places and everything is fine
source share