Javascript nodeValue returns null

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

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

Some text
3条回答
  •  误落风尘
    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);
    }
    

提交回复
热议问题