I have a plugin that finds all img elements within a given parent element. Some of the images are duplicates that I need to remove from the array. I’m thinking I can put them all into an array and then filter the duplicates out or while i’m traversing the map do some sort of conditional check but not quite sure how to do either
jq plugin
(function( $ ){
$.fn.cacheImages = function() {
this.find('img').map(function(){
if($(this).attr('data-src') == null ||$(this).attr('data-src') == 'null'){
return;
}
else{
//do something here if $(this).attr('data-src') has not bed traversed yet
}
});
};
})( jQuery );
then called like
$('#something-with-images').cacheImages();
You could save the URLs to an object as they are used?