3
Eat I make to catch the id
in Javascript that, in HTML, is data-id="2"
?
<ul>
<li data-id="1" id="e1">Elemento 1</li>
<li data-id="2" id="e2">Elemento 2</li>
<li data-id="3" id="e3">Elemento 3</li>
</ul>
For example, for the HTML above, I would like to receive the id e2
, since this is the one that has data-id="2"
.
Why the negative? Everyone should be born knowing how to do it?
– Wallace Maxters
Thecoder, could confirm if you need to search for the element you have
data-id=2
or what you want is the value 2?– Woss
I want to search if any element has data-id=2
– The Coder
Could pick up hair
id
direct, no?– Sam
The id is just for example. I am creating an API in which the other programmer can create his own button, just put this attribute to work
– The Coder