[removed] document.getElementById() returns NULL

后端 未结 7 2050
遥遥无期
遥遥无期 2021-01-02 01:23

I am quite new with Javascript and I got a problem with document.getElementById() that always returns NULL, and that\'s driving me nuts.

I have a element in my code

7条回答
  •  礼貌的吻别
    2021-01-02 01:45

    if(document.getElementById("arect").value == null){
        alert('NULL >> '+ xx.value);
      }
    

    This code always returns null or error. If you want to see if the object exists, do the following....

    if(xx == null)
       alert('Object does not exist');
    else 
       alert('Object exists. Inner HTML: ' + xx.innerHTML);
    

    Also, div does not have value. If you want to get the html inside div, use xx.innerHTML

提交回复
热议问题