javascript - How to get only the content in the current box in js?
怪我咯
怪我咯 2017-06-26 10:51:24
0
1
655

The picture is as above, and then paste the html structure

web

javascript

css

css2.0

css3

html

5555

可视化

555

Suppose I have taken the outermost frame of second
Now I want to get the "web", "555" (a), "5555(b)" How to store the anonymous text in a variable?
I triedinnerTextwill get the text in the child node
UsechildNodes[0].nodeValuewill only get the first text node
Is it feasible to useifto determine whethernodeTypeis a text node?
I don’t know if there is a better way to directly get the text of the current box without getting the text in the child node~

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all (1)
ringa_lee
var t = document.getElementsByClassName('second')[0]; t.childNodes.forEach(function(v) { if(v instanceof Text) { console.log(v.data); console.log(v.wholeText); } });

Among them, the text node is an instance ofText(), and you can usedataorwholeTextto get text of typeString.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!