How to get the text node of an element?
P粉518799557
2023-08-24 10:28:37
<p><pre class="brush:php;toolbar:false;"><div class="title">
I am text node
<a class="edit">Edit</a>
</div></pre>
<p>I want to get the "I am text node", don't want the "edit" tag to be removed, and need a cross-browser solution. </p>
You can use the following method to get the nodeValue of the first child node
http://jsfiddle.net/TU4FB/
This takes the
content
of the selected element and applies the filter function to it. The filter function returns only text nodes (i.e. those withnodeType == Node.TEXT_NODE
).