Nice one nwhite, I see what you're saying about the workings of each method, I'll be using your method from now on. I think your wrapContent function would be a worthy addition to mootools core!
On Aug 28, 12:37 am, nwhite <[email protected]> wrote: > Your solution is far from ideal. What your doing to the DOM is brutal. Your > recreating every node in the page. By doing this any event listeners you > have on an element is lost. > > The solution I provided above is superior because its faster, and doesn't > break existing events. > > If the syntax seemed too much (a one liner) you could implement your own > method on element. > > Element.implement({ > wrapContent : function(el){ > this.adopt($(el).getChildren()).inject(el); > } > }); > > usage: > > new Element('div',{ 'id' : 'wrapper').wrapContent(document.body); > > On Thu, Aug 27, 2009 at 1:18 PM, atwork8 <[email protected]> wrote: > > > @Steve - I have no control over the html as it comes from a large CMS, > > obviously that would have been the initial solution. > > > I appreciate there are many ways of achieving the same result, the > > solution I provided seemed to be the shortest, and I wondered if there > > was a more 'moo' way of doing it. From what you are saying it would > > seem that this isn't the case. > > > Cheers > > > On Aug 27, 4:20 pm, "Steve Onnis" <[email protected]> wrote: > > > To answer your question, there are many ways to do it. > > > > I would probably do it like this.. > > > > new Element("div", {"id":"wrapper"}).set("html", > > > $(document.body).get("html")).inject($(document.body).empty()) > > > > You ask if what you showed is the best way? For me...if it works then > > great > > > :) > > > > -----Original Message----- > > > From: atwork8 [mailto:[email protected]] > > > Sent: Thursday, 27 August 2009 8:53 PM > > > To: MooTools Users > > > Subject: [Moo] wrap element's html > > > > Hi, > > > > I've checked the docs but I can't see any method for wrapping the html > > > of an element, not the whole element. If I wanted to add a wrapper > > > around the body's html is this the best way of doing it: > > > > var elBody = $(document.body); > > > elBody.set('html', '<div id="wrapper">' + elBody.get('html') + '</ > > > div>');
