<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<script>$("ul li:nth-child(3)").append("<span> - Selected!</span>");</script>
</body>
</html>
I want to select li number 3 and with :nth-child(3) but the problem is that the li tag are random sometime it can be 6 or 9 or 20 .. so how to get the last and maybe then use prev() ?
.eqaccepts negative indices, which count from the end. Note that.eqcounts on the set, not the actual child index. In your case however, the set only consists of the children of the oneul, so that doesn’t make a difference.