Basically my img src looks like this and has class name .pic:
img/folderA/..
img/folderB/..
img/folderC/..
..
img/folderZ/..
and I want add class name each of the img example if imc src equals /folderA/ then add that img class name ‘thisisA’ etc., i tried something like this but it wont work any help?
$('.pic').each(function(i){
var imgSrc = this.src;
if(imgSrc.indexOf('/folderA/')){
$(this).addClass('thisisA');
}
else if(imgSrc.indexOf('/folderB/')){
$(this).addClass('thisisB');
}
});
indexOfreturns -1 when there’s no match, and anything other than 0 is considered “true” byif.