jQuery get attribute

后端 未结 2 1908
不思量自难忘°
不思量自难忘° 2021-01-20 08:47

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

相关标签:
2条回答
  • 2021-01-20 08:58

    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);
    
    0 讨论(0)
  • 2021-01-20 09:14

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

    var image = $(this);
    
    0 讨论(0)
提交回复
热议问题