Re: Putting DIV wrapper around all code in body
- From: George Maicovschi <georgemaicovschi@xxxxxxxxx>
- Date: Sun, 30 Mar 2008 14:59:23 -0700 (PDT)
On Mar 30, 10:58 pm, Alexey Kulentsov <a...@xxxxxxxx> wrote:
andrej.kau...@xxxxxxxxx wrote:
Initial DOM
<body>...
<div>
<p>Some text</p>
Modified DOM with javascript
<body>...
<div id="myWrapper">
<div>
Any idea?
HTML
<head>
<script>
function addDiv()
{
// get body tag
var body=document.getElementsByTagName('body').item(0);
// create div element
var div=document.createElement('div');
// demonstrate it
// set id here if you want
div.style.border='1px solid red';
div.style.padding='0 1ex';
// while here is child in body..
var e;
while(e=body.firstChild)
// move it to div
div.appendChild(e);
// append div to body
body.appendChild(div);
}
</script>
</head>
<body onload="addDiv()">
<div>
<p>Some text</p>
<p>More text</p>
</div>
</body>
/HTML
From personal experience I know that moving a LOT of elements (orcreating 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? :-/
.
- Follow-Ups:
- Re: Putting DIV wrapper around all code in body
- From: Alexey Kulentsov
- Re: Putting DIV wrapper around all code in body
- From: RobG
- Re: Putting DIV wrapper around all code in body
- References:
- Putting DIV wrapper around all code in body
- From: andrej . kaurin
- Re: Putting DIV wrapper around all code in body
- From: Alexey Kulentsov
- Putting DIV wrapper around all code in body
- Prev by Date: Re: getElementByName within containing DIV
- Next by Date: Re: Putting DIV wrapper around all code in body
- Previous by thread: Re: Putting DIV wrapper around all code in body
- Next by thread: Re: Putting DIV wrapper around all code in body
- Index(es):
Relevant Pages
|