Uncaught TypeError: Cannot set property innerHTML of null

PloMar
Posts: 48

Uncaught TypeError: Cannot set property innerHTML of null

I have this JS script:

Code: Select all

<script>
function blockToggle(type,blockee,elem){
   var conf = confirm("Press OK to confirm the '"+type+"' action");
   if(conf != true) return false;
   var elem = document.getElementById(elem);
   elem.innerHTML = 'please wait ...';
}
</script>

In console it shows this error:

Code: Select all

Uncaught TypeError: Cannot set property 'innerHTML' of null

What is the cause and how to fix it?

MarPlo
The error message indicates that there is not a HTML element in page with the id passed in the "elem" arguments.
Check the part of your JavaScript code where that function is accessed to see what id is passed to the "elem" parameter, then make sure you have a HTML element with that id in webpage.

Adv. Posts: 01

Similar Topics