Hi Nathan - I'll take a stab at it!
A while back I wrote a nifty little pair of plugins: http://john.jquery.com/jquery/test/nextuntil.html .nextUntil() and .wrapAll(). wrapAll is perfect for you, unfortunately, nextUntil won't do the trick - you need a .nextAll() So here's a .nextAll: $.fn.nextAll = function() { var match = []; // We need to figure out which elements to push onto the array this.each(function(){ // Traverse through the sibling nodes for( var i = this.nextSibling; i; i = i.nextSibling ) { // Make sure that we're only dealing with elements if ( i.nodeType != 1 ) continue; // Otherwise, add it on to the stack match.push( i ); } }); return this.pushStack( match ); }; And now we can do this: $("div.accoridan h3").nextAll().wrapAll("<div class='accordianInner'></div>"); I think that's a pretty nifty solution :-) Let me know if you want me to setup a demo. --John On 2/12/07, Nathan Young -X (natyoung - Artizen at Cisco) <[EMAIL PROTECTED]> wrote: > Hi All. > > I want to accordion an existing content format, and I think that I need > to insert a wrapper element. First I would love a sanity check on my > general approach then maybe someone can critique the manipulation I'm > trying. > > Here's my content: > > <div class="accordion"> > <h3>heading</h3> > <arbitrary content/> > </div> > > I can't change the content and I need the heading to be used as the > clickable bar. > > The approach I want to take (on a high level) is: > - put a div around everything after the h3 in the dives classed > "accordion" > - put events on the h3 to show the associated div and hide the > non-associated divs > > The js I would use is something like: > > $("[EMAIL PROTECTED]").removeClass("accordion").addClass("accordionI > nner"); > $("[EMAIL PROTECTED]").wrap('<div class="accordion"></div>'); > > //no luck here: > $("div:[EMAIL PROTECTED]").each(function(i){$(this).prepend($(this).chi > ldren("[EMAIL PROTECTED]:firstChild)}) > > //nor with this: > $("[EMAIL PROTECTED]").each(function(i){$(this).children("[EMAIL PROTECTED] > =accordionInner]:first-child").clone().prependTo(this)}) > > > All suggestions welcome! > > ----------->Nathan > > > > .:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.: > ||:. > > Nathan Young > Cisco.com->Interface Development > A: ncy1717 > E: [EMAIL PROTECTED] > > _______________________________________________ > jQuery mailing list > [email protected] > http://jquery.com/discuss/ > _______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
