Yeah, absolutely, I understand the normal application of it, but since it’s not a deep copy/clone, it doesn’t make any difference (to my knowledge). And if it was a deep copy then the reference to the node in the DOM would be severed so manipulating it wouldn’t affect any of the elements on the page, so that aspect wouldn’t be desirable anyway. XD

And as u/intramatic, pointed out using document.querySelector() would yield the first item directly, so would have been the most straightforward choice.

I’m not really criticizing or anything, my guess is that the function might have started out with handling all occurrences and was then trimmed down to its bare minimum without refactoring.

But when it comes to JavaScript there are so many odd little behaviors and tricks that it’s worth asking to see if there’s a nugget of knowledge I’ve missed before, or if it’s just a happenstance/result of quick and dirty coding.

Read More