9
On the page there are several elements with attributes data
. To avoid going around adding CSS classes to the elements, making page code denser, I would like to select elements by attribute name data
.
Example
<div id="myDiv" class="text banana" data-my-target="John"></div>
<div id="myOther" class="text bread" data-my-target="Doe"></div>
<div id="myBother" class="text fun" data-my-girl="Jane"></div>
The idea is to apply a certain action via jQuery to elements containing an attribute data-my-target
.
Question
How can I select elements by attribute name data
?
how can I select the value of the attribute ?
– Murilo Melo