Example 1 — Official Demo: ul li:nth-last-of-type(2)
Mark the second-to-last li in every list (jQuery API example).
$("ul li:nth-last-of-type(2)").each(function () {
this.textContent = this.textContent + " - 2nd to last!";
});
console.log($("ul li:nth-last-of-type(2)").length); How It Works
- Group by tag. Only
lisiblings are numbered. - Count from the end. Last
liis 1; previousliis 2. - One per list. Each
ulcontributes its penultimateli.

