wrapper - How to wrap 1-2 or more of the same class using JQuery but not getting to wrap it with a different class in between? -


to make visually understandable, want this:

<div class="wrap">     <input type="hidden" />     <input type="hidden" />     <div class="a">content</div>     <input type="hidden" />     <input type="hidden" />     <input type="hidden" />     <div class="a"></div>     <input type="hidden" />     <div class="a"></div>     <input type="hidden" />     <input type="hidden" />     <div class="bee"></div>     <input type="hidden" />     <input type="hidden" />     <div class="a"></div>     <input type="hidden" />     <input type="hidden" />     <div class="cee"></div>     <input type="hidden" />     <input type="hidden" />     <input type="hidden" />     <div class="a"></div>     <input type="hidden" />     <input type="hidden" />     <input type="hidden" />     <input type="hidden" />     <div class="a"></div> </div> 

to become this:

<div class="wrap">     <div class="jquerywrap">         <input type="hidden" />         <input type="hidden" />         <div class="a">content</div>         <input type="hidden" />         <input type="hidden" />         <input type="hidden" />         <div class="a"></div>         <input type="hidden" />         <div class="a"></div>     </div>     <input type="hidden" />     <input type="hidden" />     <div class="bee"></div>     <div class="jquerywrap">         <input type="hidden" />         <input type="hidden" />         <div class="a"></div>     </div>     <input type="hidden" />     <input type="hidden" />     <div class="cee"></div>     <div class="jquerywrap">         <input type="hidden" />         <input type="hidden" />         <input type="hidden" />         <div class="a"></div>         <input type="hidden" />         <input type="hidden" />         <input type="hidden" />         <input type="hidden" />         <div class="a"></div>     </div> </div> 

the html inside wrap auto generated have walk path of jquery.

edit: forgot mention, there 1 or more hidden type input above every siblings in ".wrap" class

you can find .a elements previous sibling not .a element(ie start of each block) find contiues .a siblings , call wrapall() like

$('.wrap .a').not('.a + .a').each(function () {     $(this).nextuntil(':not(.a)').addback().wrapall('<div class="jquerywrap"/>') }) 

demo: fiddle


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -