469,337 Members | 6,005 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,337 developers. It's quick & easy.

Putting DIV wrapper around all code in body

I need to put all body content into wrapper when page is loaded. Via
javascript of course.

Initial DOM

<body>
<div>
<p>Some text</p>
<p>More text</p>
</div>
</body>

Modified DOM with javascript
<body>
<div id="myWrapper">
<div>
<p>Some text</p>
<p>More text</p>
</div>
<div>
</body>

Any idea?
Mar 30 '08 #1
3 1351
Guys, thanks a lot.
It really solved my problem. I was trying approach with "appendChild"
but totaly forgot that when first child is moved into div than next
child is now firstChild :-). I will test this solution with innerHTML
also to compare speeds.
Thanks a lot.
Mar 31 '08 #2
George Maicovschi wrote:
From personal experience I know that moving a LOT of elements (or
creating a LOT of new ones) can cause the browser to move slowly and
make a user experience not so nice, so this method shouldn't be used
on very large pages.

Couldn't we try an approach using the innerHTML? :-/
In any case browser need to remove all elements from body and insert
them to DIV, but in the case of innerHTML here is additional conversion
from DOM to HTML (text=body.innerHTML) and then back from HTML to DOM
(div.innerHTML=text) so I don't think it's more fast then direct moving.
Mar 31 '08 #3
On Mar 31, 10:16 am, andrej.kau...@gmail.com wrote:
Guys, thanks a lot.
It really solved my problem. I was trying approach with "appendChild"
but totaly forgot that when first child is moved into div than next
child is now firstChild :-). I will test this solution with innerHTML
also to compare speeds.
Thanks a lot.
Hey Andrej, just post here your conclusions about the speed of the two
methods, I'm quite curious about them results on your script, since I
am using innerHTML now for something similar because when using
appendChild on a high number of elements in Firefox the memory
requests of Firefox just went up a whole lot.

Regards,
George Maicovschi.
Mar 31 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by dedejavu | last post: by
15 posts views Thread by Steve Richfield | last post: by
reply views Thread by DotNetJunkies User | last post: by
3 posts views Thread by markww | last post: by
16 posts views Thread by utab | last post: by
9 posts views Thread by ma740988 | last post: by
4 posts views Thread by Doug Laidlaw | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.