Is there any possibility to get all HTML content elements that contains “plain” text values from HTML document using javascript?
For example:
<html>
<body>
<div>
Text1
<p>
Text2
</p>
</div>
</body>
</html>
I want to get Text1 and Text2.
Sure, you can simply iterate over the DOM nodes:
This is a recursive approach, you can also select all element nodes first and then get their child text nodes.
You probably also want to filter out text nodes only containing whitespaces.
DEMO