Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  131] [ 4]  / answers: 1 / hits: 39734  / 11 Years ago, mon, february 25, 2013, 12:00:00

I have a series of images each with the class photo;



I want to go through each of these and retrieve the photo source, for use later in an if statement. I have written the below code to do this, but have not been successful:



$.each($(.photo), function() {
var imgsrc = $(this).attr(src).length;
console.log(imgsrc);
});


I am not sure where I have gone wrong here. It seems to make sense to me, but I dont get anything in the console.



Can anyone point me in the right direction?


More From » jquery

 Answers
37

If you have given same class name for all img tag then try this ,



  $(.photo).each(function() {  
imgsrc = this.src;
console.log(imgsrc);
});

[#80026] Saturday, February 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristopherh

Total Points: 402
Total Questions: 117
Total Answers: 84

Location: Monaco
Member since Fri, Sep 24, 2021
3 Years ago
;