3
<div>
  <p>Hello World!</p>
foo
</div>

I want to get only the text of the text nodes inside the div, and I can't use $('div').text() because that gives me the text of the p also.

Actually I would like to get the text of every such text node, and I hope there's something as simple as $('textNode').toArray().map((node) => $(node).text()).

ggorlen
  • 44,755
  • 7
  • 76
  • 106
GirkovArpa
  • 4,427
  • 4
  • 14
  • 43
  • Try: `var node = document.getElementById('test');textContent = node.textContent;` – Kevin M. Mansour Aug 10 '21 at 22:24
  • Does this answer your question? [How to get a text that's separated by different HTML tags in Cheerio](https://stackoverflow.com/questions/73690939/how-to-get-a-text-thats-separated-by-different-html-tags-in-cheerio) – ggorlen Nov 26 '22 at 00:02

0 Answers0