Text nodes? Requesting .contents()
See original GitHub issueI’m trying to get text nodes with cheerio and I cannot find a way to do this. The only way that I am aware of is calling .contents() in jQuery to retrieve all elements (including text nodes and comment nodes). Example:
var markup = '<div>Something <b>bold</b></div>';
var $ = cheerio.load(markup);
console.log($('div').contents().first().text()); // "Something "
Issue Analytics
- State:
- Created 11 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Node.textContent - Web APIs | MDN
The textContent property of the Node interface represents the text content of the node and its descendants.
Read more >How to get the text node of an element? - Stack Overflow
I will update the answer to show it. You need text() because the the filter function returns the nodes themselves, not the contents...
Read more >Chapter 16: HTML Text Nodes in JavaScript - Medium
This is correct because our querySelector() selects the second p element. ... To see what this text content is, we can ask for...
Read more >Anatomy of an HTTP Transaction | Node.js
When an HTTP request hits the server, node calls the request handler function with a few handy objects for dealing with the transaction,...
Read more >Replacing Text Nodes With jQuery - Ben Nadel
In rare cases, however, we do want to get at the Text nodes contained within an element. To do this, we can use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That is indeed pretty easy, thanks for the hints. I didn’t actually jump into the source code yet, but I’ve just edited my second response with the proper implementation (I guess). It would be nice to have this appear in the official branch at some point. Thanks for the feedback!
Ah, indeed. I missed that. I guess it will become something like this