Adding class to first child
I'm struggling to work out where in this code do I add something to give my first child of the div#slideshow a class of active.
function heroSliders() { var $active = $('#slideshow img.active'); if ( $active.length == 0 ) $active = $('#slideshow img:last'); // use this to pul the divs in the order they appear in markup var $next = $active.next().length ? $active.next() : $('#slideshow img:first'); $active.addClass('last-active'); $next.css({opacity: 0.0}) .addClass('active') .animate({opacity: 1.0}, 1000, function() { $active.removeClass('active last-active'); }); } $(function() { setInterval( "heroSliders()", 3000 ); });
Basically the list of images I am using are pulled dynamically, so I need to use jQuery to apply a class of active to the first element - this is so it prevents all the images loading at once and causing a flicker.
I have learned that I may need to use the first(); code - but I don't know where to add this code.