Example 1 — Official Demo: span:nth-of-type(2)
Find each span that is second among its sibling spans (jQuery API example).
$("span:nth-of-type(2)").each(function () {
this.textContent = this.textContent + " is 2nd sibling span";
});
console.log($("span:nth-of-type(2)").length); How It Works
- Group by parent. Each container numbers its own spans.
- Count only spans. Other tags (if any) do not change span indexes.
- Keep index 2. The second span in each group matches.

