Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You don’t have to call getElementById or querySelector on document. You can narrow the search by starting at a specific node, just most people default into document as it’s already a global.


> You don’t have to call getElementById or querySelector on document.

You do have to call `getElementById` on a document. There can be many documents in a window.


Ah yes correct on getElementById, especially as every id must be unique.


> especially as every id must be unique.

Although a very consistent convention, there are no guardrails put in place to prevent something from setting the same id on two or more elements.

getElementById will return the first element that it finds with the id, but you can't know for sure if it is the only one without additional checks




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: