D
D
deemaagog2020-04-28 11:56:46
JavaScript
deemaagog, 2020-04-28 11:56:46

Cheerio how to get html between two elements?

How to get html between two elements?
You need to get everything from the first h2 to the second, including text, tags, nested tags, but not including the h2 itself and its content.

<h2><b>Version 0.3.0</b></h2>
April 15, 2020
<span>What’s new</span>
<h2><b>Version 0.2.9</b></h2>


const content = $('h2')
      .first()
      .nextUntil('h2');
    console.log($.html(content));

I try this, but I only get . And you need everything, including the text:
<span>What’s new</span>

April 15, 2020
<span>What’s new</span>

Thanks in advance

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question