I''m trying to find the cleanest way to do the following: I want to have a class that takes a div''s id as the argument and then creates another div to wrap around the first, without changing anything about the original div. <div id="stuff"></div> new Foo(''stuff'') would result in <div id="foo"><div id="stuff></div></div> I''m looking at the Insertion classes, but there doesn''t seem to be an Insertion.Around, and the best thing I can come up with is to create the new wrapper div, initially empty, then copy the target div and insert it as the first child and then delete the target div. This seems messy and potentially complicated if I have to eval any JS or un-register any JS handlers in the original div. I''d like my class to know as little about the original div as possible. Thanks. -- Michael Peters Developer Plus Three, LP --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
This example doesn''t really use any of prototype''s functionality beyond the $ function, but it is still small enoguht. The first 3 lines are just setup lines, the last two specifically deal with attaching the elements to the DOM. I believe there is a function that will reproduce the 2nd to last line as a function call, but for the life of me I can''t remember what it is named. Either way, typing out the actual code is just as fast (if not faster). - - var outerDiv = document.createElement( "DIV" ); - outerDiv.id = "foo"; - var innerDiv = $("stuff"); - - innerDiv.parentNode.appendChild(outerDiv); - outerDiv.appendChild( innerDiv ); -Andrew Martinez -----Original Message----- From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org]On Behalf Of Michael Peters Sent: Thursday, November 09, 2006 11:18 AM To: Prototype/Scriptaculous Subject: [Rails-spinoffs] creating a wrapper div I''m trying to find the cleanest way to do the following: I want to have a class that takes a div''s id as the argument and then creates another div to wrap around the first, without changing anything about the original div. <div id="stuff"></div> new Foo(''stuff'') would result in <div id="foo"><div id="stuff></div></div> I''m looking at the Insertion classes, but there doesn''t seem to be an Insertion.Around, and the best thing I can come up with is to create the new wrapper div, initially empty, then copy the target div and insert it as the first child and then delete the target div. This seems messy and potentially complicated if I have to eval any JS or un-register any JS handlers in the original div. I''d like my class to know as little about the original div as possible. Thanks. -- Michael Peters Developer Plus Three, LP --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Martinez, Andrew a écrit :> This example doesn''t really use any of prototype''s functionality beyond the $ function, but it is still small enoguht. The first 3 lines are just setup lines, the last two specifically deal with attaching the elements to the DOM. I believe there is a function that will reproduce the 2nd to last line as a function call, but for the life of me I can''t remember what it is named. Either way, typing out the actual code is just as fast (if not faster). > - > - var outerDiv = document.createElement( "DIV" ); > - outerDiv.id = "foo"; > - var innerDiv = $("stuff"); > - > - innerDiv.parentNode.appendChild(outerDiv); > - outerDiv.appendChild( innerDiv );Almost. This could move the original div to an undue position. You''d have to insert the new outer div at the same DOM position. You can do this by merely changing the penultimate line to this: innerDiv.parentNode.insertBefore(outerDiv, innerDiv); That will do the trick. -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---