开发者

jQuery - Get title attribute using each

开发者 https://www.devze.com 2023-04-12 14:59 出处:网络
I have this jquery code: $.each(\'.button.gobutton\', function() { alert($(this).attr(\'title\')); }); I basically want to iterate 开发者_如何学Cthrough each element and get the value of the title

I have this jquery code:

$.each('.button.gobutton', function() {
      alert($(this).attr('title'));
 });

I basically want to iterate 开发者_如何学Cthrough each element and get the value of the title for each element. However when I run this code I get undefined for all the values. Below is the html:

<button class="button gobutton" title="2">GO</button>


$.each iterates over arrays/objects. It doesn't select DOM elements.

It seems like you're trying to do this:

$('.button.gobutton').each(function() {
      alert($(this).attr('title'));
});
0

精彩评论

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

关注公众号