Javascript: getElementById vs getElementsById (both works on different pages)

As described by James here id values have to be unique in a document, so there will be only one “element” that matches, rather than multiple “elements”.

That is the reason, We should not use s while selecting elements. As Id can be selected only one at a time.

However, there are methods that return multiple elements which do use the plural “elements”, such as getElementsByTagName.

Hope that clears your confusion

Leave a Comment