I am looking to use jQuery contains to run through each image on a page and check if the src tag contains a certain http value. How would I run a check on the text in the src attribute with jQuery or javacript. I have the overview of what I am attempting below:
$('img').each(function(i){
var img = $(this),
imgSrc = img.attr('src'),
siteURL = "http://url.com";
if(!imgSrc.contains(siteURL)){
imgSrc = siteURL + imgSrc;
}
});
I have a feeling regex may be the way to go just don’t know how for sure.
1 Answer