admin管理员组文章数量:1323335
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!
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!
Share Improve this question asked Mar 10, 2010 at 10:42 n00bn00b 16.6k21 gold badges58 silver badges72 bronze badges2 Answers
Reset to default 8You 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);
本文标签: javascriptjQuery get attributeStack Overflow
版权声明:本文标题:javascript - jQuery get attribute - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742136838a2422407.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论