2009/11/19 hagbardceline <hagbardcelin...@gmail.com> > @Michel > > Yes, basically you're totally right. Your script is much nicer and > does not nest loops. > Logic is not exactly as it should be. > > The idea is: > > After each closing h3 tag (</h3>) inside modAccordion container append > an opening div (<div>) tag. > Before every opening h3 tag (<h3>) but not before the first opening h3 > tag add a closing div (</div>) tag. > Finally before the closing div tag from the modAccordion container, > add a closing div (</div>) tag. >
Isn't it what my script does precisely ? $(".modAccordion > h3").each(function() { var switch = true; $(this).nextAll() .select(function() { return switch && (switch = ! $(this).is('h3')); }) .wrapAll('<div class="new"></div>'); }); line 1 : round all h3 in .modAccordion and for each line 3 : | select all next elements line 4 : | | pick those of these elements that are just before the next h3 (the resulting selection is placed between current h3's closing tag and next h3's opening tag) line 5 : | | wrap all these elements in one and the same div with class="new" (between current h3 and next h3 according to line 4) > But you got me close! > Thanx anyway, I appreciate your help. > > As long as you're close that's fine by me anyway. Kind regards. Michel Belleville