Javascript nodeValue returns null

后端 未结 3 973
生来不讨喜
生来不讨喜 2021-01-04 19:15

Title should make my problem well described.Here goes my code.

Some text
相关标签:
3条回答
  • 2021-01-04 19:29

    You are missing a firstChild:

    alert(document.getElementById("adiv").firstChild.firstChild.nodeValue);
    

    (I know it sounds weird but this is how text nodes work)

    0 讨论(0)
  • 2021-01-04 19:41

    In order to get [merged] text content of an element node:

    function vb(){
    var textnode = document.getElementById("adiv").firstChild;
    alert(textnode.textContent || textnode.innerText);
    }
    

    In order to get text content of a text node:

    function vb(){
    alert(document.getElementById("adiv").firstChild.firstChild.nodeValue);
    }
    
    0 讨论(0)
  • 2021-01-04 19:50

    <text> node is not supported in IE 7.

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