jQuery get attribute

后端 未结 2 1909
不思量自难忘°
不思量自难忘° 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);
    

提交回复
热议问题