jQuery - Get title attribute using each
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'));
});
精彩评论