How do I, with the clearest syntax, find the second element with the data-id 411
?
<div data-id="410">Yo</div>
<div data-id="411">No</div>
<div data-id="412">Mm</div>
How do I, with the clearest syntax, find the second element with the data-id 411
?
<div data-id="410">Yo</div>
<div data-id="411">No</div>
<div data-id="412">Mm</div>
$("div[data-id=411]").text("Hello")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div data-id="410">Yo</div>
<div data-id="411">No</div>
<div data-id="412">Mm</div>
Something as simple as this should work. Jason is right though, the jQuery website has some great documentation.
You want to assign a class name to the elements you are searching from, so that it's not looking at the whole document.
<div class="search">
<div data-id="410">Yo</div>
<div data-id="411">No</div>
<div data-id="412">Mm</div>
</div>
var element = $('.search').find("div[data-id='411']");