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

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -