jquery - Add wrapper after ever second div -
i'm trying add wrapper around ever second div include first , second divs
js
$('.block').wrap('<div/>');
the desired effect result in this
html
<div><-- added js --> <div class="block"> <div class="content"> block 1 </div><!--content end --> </div><!--block end --> <div class="block"> <div class="content"> block 2 </div><!--content end --> </div><!--block end --> </div><-- added js --> <div><-- added js --> <div class="block"> <div class="content"> block 3 </div><!--content end --> </div><!--block end --> <div class="block"> <div class="content"> block 4 </div><!--content end --> </div><!--block end --> </div><-- added js --> <div><-- added js --> <div class="block"> <div class="content"> block 5 </div><!--content end --> </div><!--block end --> <div class="block"> <div class="content"> block 6 </div><!--content end --> </div><!--block end --> </div><-- added js -->
select every other .block
element, add next .block
element 2 , 2 together, , wrapall div :
$('.block:even').each(function() { $(this).add( $(this).next('.block') ).wrapall('<div />'); });
Comments
Post a Comment