How To Get Only Text Node From Parent Using Node.js and Cheerio

Last updated on 8 Aug, 2021

Here is our HTML. The parent element has a child element(s) and immediate text nodes.


Inside div, we have an inner element(span) and also a text node(999). We need to extract only the text 999.

Using cheerio, we can do it like this:

  .filter(function () {
    return this.type === "text";
--- ○ ---
Joby Joseph
Web Architect