I’ve basically got a little function called findItem() that is supposed to be finding the elements I’m looking for based on custom data- attributes on the element.
In this case these are purely numerical eg. data-slide=1.
I’m a bit clueless as to how to match the value of each item’s data-slide to one that is contained within the other array.
Here is a more concrete example:
function findItem(count) {
var collection = [];
$.each(allMyLiItems, function(i, item) {
if ( $(item).data('slide') == count ) {
collection.push(item);
}
});
return $(collection);
}
findItem([1,3])
which does not work because count inside the if statement does not seem to match anything.
The page does contain 4 <li data-slide="{number}">… elements so 1,3 should return the first and third of those elements.
What am I doing wrong here?
Use
jQuery.grepandjQuery.inArray:Working example