Re: Putting DIV wrapper around all code in body



andrej.kaurin@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
.



Relevant Pages

  • Re: Putting DIV wrapper around all code in body
    ... // get body tag ... var body=document.getElementsByTagName.item; ... but the value returned by innerHTML is not necessarily the same ...
    (comp.lang.javascript)
  • Re: Putting DIV wrapper around all code in body
    ... // get body tag ... var body=document.getElementsByTagName.item; ... but the value returned by innerHTML is not necessarily the same ...
    (comp.lang.javascript)
  • Thumbnail Viewer adjusting
    ... here is simple and compact image viewer script, I'm satisfied with it, but ... as a thumbnail), resize it dynamically for thumbnail, so this did not ... //write out HTML for Image Thumbnail Viewer plus loading div ... var ie=document.all &&!window.opera ...
    (comp.lang.javascript)
  • Re: Help needed for a expand-collapse menu
    ... function getParentByTag(element, tag) { ... var div = getParentByTag; ... if (!div) return; // Fail silently ... so I need help with the collapse part and this is how I would like to ...
    (comp.lang.javascript)
  • RE: IE 7 Appears to Hang after JScript runs (code works in IE 5.5 & IE
    ... and all the JavaScript is in .js files. ... The div contains a list, user selects something and the onMouseUp event ... IE7 window or otherwise moves focus off, ... var iXOffset = oDivDdn.style.width; ...
    (microsoft.public.scripting.jscript)