javascript - Get all child nodes of div using cheerio? -


<div class="hello">   text1   <li>text2</li>   <div class="bye">text3</div>   text4 block   <div class="bye">text5</div>   last text5 </div> 

so have above grab in cheerio using $('div.hello'). want iterate through it. how iterate through including text nodes? tried using $('div.hello').contents() isn't grabbing text nodes("text1, "text4 block", , "last text5"). end goal split html block when reach first element has class of "bye". want array holding following html strings,

final_array = ['text1 <li>text2</li>', '<div class="bye">text3</div> text4 block <div class="bye">text5</div> last text5'] 

you try use map or filter methods.

for example:

var text = $('div.hello').contents().map(function() {     if (this.type === 'text')         return $(this).text().trim() }).get() 

basically in callback function need play if's want.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -