JQuery selector to find the first child in each element set
I have this HTML:
<div id="tags">
<ul>
<li><input type="text" /><a href="#">First Link</a> <a href="#">Second Link</a></li>
<li><input type="text" /><a href="#">First Link</a> <a href="#">Second Link</a></li>
<li><input type="text" /><a href="#">First Link</a> <a href="#">Second Link</a></li>
<li><input type="text" /><a href="#">First Link</a> <a href="#">Second Link</a></li>
<li><input type="text" /><a href="#">First Link</a> <a href="#">Second Link</a></li>
</ul>
</div>
Which selector would I use to grab the first anchor of each li element, and what about the second binding of each li without adding additional identifiers or classes?
Well, I tried this:
$('#tags a:last-child')
And I was able to get the second binding of each li, but I do not understand why this works. Shouldn't the element be inside the anchor in order to select something else, but it can select the second anchor of each li. Later, I didn’t care how it worked while it was working, so I suppose I will do the same to get the first element, which would be the following:
$('#tags a:first-child')
However, this does not work to get the first binding of each li. Any ideas?
EDIT: , , , , , , , . , ?
+3
4