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
beautifulsoup
checkstyle
codenvy
object
mjml
zend-framework
sitecore
switch-statement
emscripten
pyqt4
retrofit2
special-characters
openbugs
atlassian
scrolltop
docx
searchview
dynamic-sql
intershop
google-container-registry
sse
selinux
gulp-watch
php-mysqlidb
tosca
dynamically-generated
data.stackexchange.com
moses
maze
winexe
corenlp-server
panoramas
scatter3d
installshield-le
navigator
openalpr
release
filesystemwatcher
diacritics
demo
cin
hackintosh
android-softkeyboard
escpos
naming
sharp-snmp
importerror
rfc3339
xbmc
magento-2.0.7
jquery-ui-draggable
globalize
netbeans6.8
aquamacs
stdmap
dt
janus
offline.js
django-1.10
chromium-os
redbeard-ios
resourcemanager
neon
cfchart
mediametadataretriever
yajsw
html-to-pdf
aspen
libvlc
computer-architecture
ons-api
extjs-grid
text-search
cgi-bin
dronekit-android
sha512
rdflib
snackbar
phpldapadmin
browserify-shim
pseudo-class
metatrader5
punycode
nsmenu
codeplex
dsym
gwt-openlayers
windows-phone-8-sdk
rolify
asdf
dolby-audio-api
pclzip
device-width
intersect
xcode3.2
dajaxice
thttpd
koken
jquery-address
android-holo-everywhere
u2netdk
ie-compatibility-mode
product-management

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