jquery - Wrap each group of elements with class starting with same characters -


here fiddle http://jsfiddle.net/7habq/12/ of have far. want wrap groups of 'ok' starting classes own <div class="wrapper">

i figured 1 possibility take first element of each group, run nextuntil() till finds element class not matching class, wrapall.

it should in en this:

<div class="foo">aaa</div> <div class="wrapper">     <div class="ok-4">bbb</div>     <div class="ok-21887">ccc</div>     <div class="ok-6">ddd</div> </div> <div class="bar">eee</div> <div class="baz">fff</div> <div class="wrapper">     <div class="ok-5a4">ggg</div>     <div class="ok-12">hhh</div> </div> <div class="bim">iii</div> 

to wrap every individual div can use .wrap():

$('div[class^="ok"]').wrap("<div class='wrapper'></div>"); 

working demo


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -