<body>
<div>foobar</div>
<span>foo</span>
<span>bar</span>
</body>
To select the last (the second) span using nth-child:
document.querySelector("body >span:nth-child(3)");
To select the last (the second) span using nth-of-type:
document.querySelector("body >span:nth-of-type(2)");
No comments:
Post a Comment