Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
109
rated 0 times [  110] [ 1]  / answers: 1 / hits: 17554  / 13 Years ago, wed, august 31, 2011, 12:00:00

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.


More From » jquery

 Answers
5
// find all img's without the siteURL, and add it
$('img:not([src^=http://url.com])').each(function(i){
this.src = siteURL + this.src;
});

[#90327] Tuesday, August 30, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stefanicarolinat

Total Points: 145
Total Questions: 91
Total Answers: 93

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
stefanicarolinat questions
Mon, Nov 15, 21, 00:00, 3 Years ago
Fri, Apr 16, 21, 00:00, 3 Years ago
Thu, Oct 15, 20, 00:00, 4 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
;