Reputation: 11720
I have a form with a bunch of text elements, some of which have a data attribute set.
I want to loop through all the elements that have that attribute, extracting the attribute.
I've created a fiddle here.
var textInputs = $(':text');
alert('found ' + textInputs.length + ' textInputs');
var datas = textInputs.find('[data-foo]');
alert('found ' + datas.length + ' datas');
I'm finding the text elements, but my selector on the data attribute is returning no elements.
Ideas would be helpful...
Upvotes: 2
Views: 2992
Reputation: 12447
The [data-foo]
selector is correct, but you should use it in a filter
, instead of in a find
:
var datas = textInputs.filter('[data-foo]');
Upvotes: 3