JQuery get attribute

I am trying to get the original attribute of all images with a specific div, but for some reason it tells me that the .attr () function does not exist ...

What a function. Firebug also tells me that "this" is an image element. I am using jQuery v1.3.2

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

Any idea how to fix this?

Thanks in advance!

+3
source share
2 answers

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

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

or you can use

var image = this;
alert(image.src);
+8
source

this is really an image element, and you need it to be a jQuery element:

var image = $(this);
0
source

Source: https://habr.com/ru/post/1736278/


All Articles