Getting the contents of an element WITHOUT its children

前端 未结 5 1469
醉话见心
醉话见心 2020-12-10 11:18

I have a mild preference in solving this in pure JS, but if the jQuery version is simpler, then jQuery is fine too. Effectively the situation is like this

&l         


        
5条回答
  •  清歌不尽
    2020-12-10 11:52

    If you just want the first child then it's rather simple. If you are looking for the first text-only element then this code will need some modification.

    var text = document.getElementById('thisone').firstChild.nodeValue;
    alert(text);
    

提交回复
热议问题