I’m trying to wrap all of the elements between two headings regardless of what they are without having to add classes. Example:
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function () {
$(".axxs-accordion > :header").addClass("h-trigger static").next().wrap("<div class='section collapsed'></div>");
});
</script>
<div class="axxs-accordion">
<h2>Section with a Paragraph</h2>
<!-- wrap here -->
<p>Here is some text content</p>
<!-- to here -->
<h2>Section with a Div and Mixed Content</h2>
<!-- wrap here -->
<h3>Heading</h3>
<p>Here is some content with text and a link.</p>
<p><a href="#" target="_blank">Test link</a></p>
<!-- to here -->
<h2>Section with a List</h2>
<!-- wrap here -->
<ul>
<li>List item 1</li>
<li>List item 2</li>
</ul>
<!-- to here -->
</div>
Obviously it works in the first and third sections, because there is only one element after the H2. But how do I wrap the group of elements in the second section? I’ve seen other posts about nextUntil, but those all of those examples had classes to work off of.