I want to use html data-* attributes and have the following images:
<img src="http://placehold.it/100.png" data-selected="true"> <img src="http://placehold.it/100.png" data-selected="false"> <img src="http://placehold.it/100.png" data-selected="false"> <img src="http://placehold.it/100.png" data-selected="true"> <img src="http://placehold.it/100.png" data-selected="false">
how now can I get only those with data-selected="true" ?
I tried:
$("img").each(function(){ if($(this)).attr("data-selected") == "true") { //do something } }
but that doesn't seem to be the best way for me. Is there a direct selector where I can do something like
$("img data-selected=true") ?
thank you for your help!
javascript jquery html5
Bfar221
source share