Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery get attribute

I'm trying to get the source attribute of all images withing a specific div but somehow it keeps telling me that the function .attr() doesn't exist...

That's the function. Firebug also tells me that "this" is an image element. I'm using jQuery v1.3.2

$('#products LI DIV IMG').each(function() { 
  var image = this;
  alert(image.attr('src'));
});

Any idea how to fix that?

Thanks in advance!

like image 213
n00b Avatar asked Jul 14 '26 08:07

n00b


1 Answers

You have to make it a jquerby object to access attr('src').

var image = $(this);
alert(image.attr('src'));

or you can use

var image = this;
alert(image.src);
like image 169
rahul Avatar answered Jul 16 '26 21:07

rahul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!