javascript - Using data attributes and jQuery how can I select elements by data attribute name AND data attribute value -
i need select elements data attribute name , data attribute value.
something (but obviously, doesn't work)
for(var i=0; i<x.length; i++){ var y = $('.my-class').attr('data-id', i); //trying select here y.html('input' + i); } have no idea how achieve this, please help! :)
you can use attribute selector
var y = $('.my-class[data-id="' + + '"]'); since selector .my-class repeated, can cache it
var els = $('.my-class'); for(var i=0; i<x.length; i++){ var y = els.filter('[data-id="' + + '"]'); //trying select here y.html('input' + i); } demo: fiddle
Comments
Post a Comment