nextUntil and wrapAll
Wrapping several Tags into one with jquery
by bjelline
HTML
<div class="meta">Wednesday, March 25, 2015 at 7:58am EDT</div>
<div class="intro">Someone posted something via Twitter.</div>
<div class="comment">Spannende Frage: gilt die Privacy Policy noch wenn der Laden nach dem Konkurs verramscht wird? http://t.co/H2VPfQveNC http://t.co/8aIuZrADMh</div>
<div class="meta">Tuesday, March 24, 2015 at 6:10am EDT</div>
<div class="intro">Someone added a new photo to the album Mobile Uploads.</div>
<div class="meta">Thursday, March 19, 2015 at 12:28pm EDT</div>
<div class="intro">Someone updated her status.</div>
<div class="comment">If you wan to go out for dinner with me in London, this is my preference: http://4sq.com/1bw7aid</div>
CSS
div {
background-color: #ddd;
margin-bottom: 5px;
}
.story {
border: 2px red dashed;
}
JavaScript
$('div.meta').each(function () {
$(this).nextUntil('div.meta').addBack().wrapAll("<div class='story'>"); //
});