cheerio


Get the text of the current node only


In Cheerio, how do you get just the text of the current node only?
var cheerio = require('cheerio')
const htmlString = '<div>hello<span>world</span></div>'
$ = cheerio.load(htmlString, { ignoreWhitespace: true })
console.log($('div').text()) //helloworld
console.log($('span').text()) //world
How do you get just hello?
You can do this:
console.log($('div').contents().first().text()) # hello

Related Links

confused about cheerio nextUntil
Get the text of the current node only
Accessing the text of a class that contains other elements using Cheerio
cheerio reading children of script tag
how to extract info in this kind of html using cheerio?
Cheerio not finding table content

Categories

HOME
azure-stream-analytics
cobalt
fuelux
time-complexity
codenvy
telegram
swt
apache-spark-mllib
bitbucket-api
pyqt4
ado.net
interpolation
google-admin-sdk
nstableheaderview
augeas
jquery-ui-sortable
ibeacon-android
plist
mautic
stellar.js
azure-iot-hub
microsoft-dynamics-nav
video-editing
soci
enterprise-miner
selinux
dataflow-diagram
easeljs
underscore.js
user-defined-functions
complex-numbers
record
rselenium
laravel-eloquent
python-import
jwplayer6
processwire
servicestack-text
apic
reason
git-rewrite-history
connection-pool
comparison-operators
trigonometry
optimizely
reportservice2010
vugen
context-sensitive-grammar
gets
node-request
pure-css
atlas
reporting-services-2012
neon
nikeplus-api
cifilter
pre-build-event
lz77
nupic
findfirst
cycle2
qbxml
xenomai
video-player
qtwebengine
document-repository
entry-point
build-script
lnk
mutual-authentication
vsx
square-bracket
composite-component
mysql-error-2013
google-maps-mobile
mysql-error-1205
strsep
cuteeditor
non-clustered-index
rowlex
isapi-extension
qtabbar
duplex
lxr
skype4java
tui

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App