JSFiddle - React, Tailwind, and code Playground
by rodneyrehm
HTML
<p class="one">one</p>
<p class="one">other one</p>
<p class="two">two</p>
<p class="two">other two</p>
<p class="three">three</p>
JavaScript
$('.one')
.css('font-weight', 'bold')
.add($('.two').get(0))
.add($('.two').get(1))
.css('background', 'red');
var $one = $('.one').first();
$('p').each(function(){
if ($(this).prev().length) {
$one.add(this);
}
});
// should be 5 paragraphs
$('<p></p>').appendTo(document.body).text($one.length + " paragraphs in $one");
$one.each(function(){
$(this).css('background', 'green');
})