Asked 3 years ago
24 Sep 2021
Views 4098
shabi

shabi posted

Javascript - Uncaught TypeError: document.getElementbyId is not a function


document.getElementbyId('id').innerHtml='new';

i am trying to change HTML of the div by id but some how i got following error
Uncaught TypeError: document.getElementbyId is not a function
not sure what is wrong in code ?
steave ray

steave ray
answered Sep 25 '21 00:00

There is a typo error in the above code, getElementById() use instead of the getElementbyId() function.
getElementById() is function used to get element by id , you need to provide id of the element to the getElementById() function and it will return object of that element.
changed and correct code is as below :

document.getElementById('id').innerHtml='new';

Post Answer