html – Javascript: getElementById vs getElementsById (both works on different pages)
html – 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
First things first:
Function-, or rather, methodnames in JavaScript are Case-Sensitive. This means that document.getElementById is not the same as document.getElementbyId.
The weird part:
document.getElementsById does not exsist in JavaScript, so it cant work by default. The only way this can work is if somebody created this function/method on the other page. A more obvious explanation is that you made a type-o on your second page. Maybe you forgot to write the S and you thought you didnt. Can you try again?