JSFiddle - React, Tailwind, and code Playground

HTML

<h3>I.</h3>
<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
</ul>
<ol>
    <li>1.</li>
    <li>2.</li>
    <li>3.</li>
</ol>
<p>Some text</p>

<h3>II.</h3>
<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
</ul>
<p>Some text</p>
<ol>
    <li>1.</li>
    <li>2.</li>
    <li>3.</li>
</ol>

<h3>III</h3>

CSS

div {
    border: 1px solid #C00;
}

JavaScript

$('h3').each(function() {
    $(this).nextUntil('h3').wrapAll('<div />');
});