Skip to content Skip to sidebar Skip to footer

Javascript: GetElementById Vs GetElementsById (both Works On Different Pages)

I'm struggling with a really weird problem... I have two pages (quite the sames) where I need to disable some selects. On one of them (say page A), I use getElementById to retrieve

Solution 1:

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


Solution 2:

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 can't 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 didn't. Can you try again?


Post a Comment for "Javascript: GetElementById Vs GetElementsById (both Works On Different Pages)"