Uncaught Typeerror: cannot read property 'innerHTML' of null

前端 未结 8 2161
遥遥无期
遥遥无期 2020-12-05 12:04

Can anyone explain what is theses errors?

Uncaught TypeError: cannot read property \'innerHTML\' of null

View on my website This

相关标签:
8条回答
  • 2020-12-05 12:57

    While you should ideally highlight the code which is causing an error and post that within your question, the error is because you are trying to get the inner HTML of the 'status' element:

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

    However the 'status' element does not exist within your HTML - either add the necessary element or change the ID you are trying to locate to point to a valid element.

    0 讨论(0)
  • 2020-12-05 13:00

    Update:

    The question doesn't ask for jquery. So lets do it without jquery:

    document.addEventListener("DOMContentLoaded", function(event) { 
        //Do work
    });
    

    Note this method will not work on IE8.

    Old Answer:

    You are calling this script before DOM is ready. If you write this code into jquery's $(function() method it will work.

    0 讨论(0)
提交回复
热议问题