I have 2 variables set like this:
var carousel = $('div.carousel ul');
var pics = carousel.children('li');
Later on a few new <li> get added to the carousel using insertBefore() however my pics variable is now out of date so I have to call pics = carousel.children('li'); again in my function.
Is there a better way of doing this without repeated traversing of the DOM?
jQuery has an
add()function which will take an argument and add that to the list of selected items. You can callpics.add(newli);any time you add a new list item to the DOM.