Last active
November 3, 2020 10:01
-
-
Save timothyjensen/260931e9ac8482ba997d3ff88e6b1187 to your computer and use it in GitHub Desktop.
Wrap sibling groups using jQuery.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$(':not(.sibling-element) + .sibling-element, * > .sibling-element:first-of-type'). | |
each(function() { | |
$(this). | |
nextUntil(':not(.sibling-element)'). | |
addBack(). | |
wrapAll('<div class="sibling-wrapper" />'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="entry-content"> | |
<div class="sibling-wrapper"> | |
<div class="sibling-element">Sibling</div> | |
<div class="sibling-element">Sibling</div> | |
</div> | |
<p>A random separator</p> | |
<div class="sibling-wrapper"> | |
<div class="sibling-element">Sibling</div> | |
<div class="sibling-element">Sibling</div> | |
<div class="sibling-element">Sibling</div> | |
</div> | |
<p>Another random separator</p> | |
<div class="sibling-wrapper"> | |
<div class="sibling-element">Sibling</div> | |
<div class="sibling-element">Sibling</div> | |
<div class="sibling-element">Sibling</div> | |
<div class="sibling-element">Sibling</div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="entry-content"> | |
<div class="sibling-element">Sibling</div> | |
<div class="sibling-element">Sibling</div> | |
<p>A random separator</p> | |
<div class="sibling-element">Sibling</div> | |
<div class="sibling-element">Sibling</div> | |
<div class="sibling-element">Sibling</div> | |
<p>Another random separator</p> | |
<div class="sibling-element">Sibling</div> | |
<div class="sibling-element">Sibling</div> | |
<div class="sibling-element">Sibling</div> | |
<div class="sibling-element">Sibling</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment