开发者

jQuery get attribute

开发者 https://www.devze.com 2022-12-22 17:07 出处:网络
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...

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 t开发者_运维知识库ells 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!


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);


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

var image = $(this);
0

精彩评论

暂无评论...
验证码 换一张
取 消