Uncaught Typeerror: cannot read property 'innerHTML' of null

Davix Ponze picture Davix Ponze · Jan 25, 2012 · Viewed 153.5k times · Source

Can anyone explain what is theses errors?

Uncaught TypeError: cannot read property 'innerHTML' of null

View on my website This is the line which is causing the error:

var idPost=document.getElementById("status").innerHTML;

Thanks

Answer

jianbo.zheng picture jianbo.zheng · Sep 26, 2012
var idPost=document.getElementById("status").innerHTML;

The 'status' element does not exist in your webpage.

So document.getElementById("status") return null. While you can not use innerHTML property of NULL.

You should add a condition like this:

if(document.getElementById("status") != null){
    var idPost=document.getElementById("status").innerHTML;
}

Hope this answer can help you. :)