How do I get the id
in JavaScript which, 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'd like to get the e2
id, since this is what has data-id="2"
.