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
url-redirection
go
embedded
scikit-learn
spark-streaming
webdriver
themes
battery
sublimetext
access
heap
frequency-distribution
do-while
modbus-tcp
searchview
powershell-v5.0
red5
imagemap
hta
object-storage
monit
definitelytyped
siri
syntax-highlighting
stackexchange
android-sharedpreferences
asymptotic-complexity
inversion-of-control
spotipy
tpm
ntp
livelink
card.io
dsx-desktop
latitude-longitude
git-rewrite-history
ods
trigonometry
watchface
stylecop
mschart
netbeans6.8
tinymce-3
semantic-logging
git-flow
restore
rocks
autosar
ziparchive
segment-io
dotnetnuke-7
eigenvector
appscale
embedding
http-status-code-401
findfirst
kendo-upload
crouton-os
google-books
cgi-bin
iced-coffeescript
atoi
airbrake
keyup
ansi
mmwormhole
ejb-2.x
webmatrix-3
viewer
addressing-mode
post-commit-hook
device-tree
rmysql
nsmenu
with-statement
rcaller
reflector
lnk
spring-remoting
radiant
sbcl
model-driven-development
observium
actiondispatch
android-icons
twisted.web
onmousemove
midlet
garbage
objectquery
jqote
unattended-processing
non-clustered-index
django-piston
lxr
sun
linfu-dynamicproxy
business-model

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