473,508 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Insert container div with DOM

I am trying to have a container div generated by the DOM, hold
everything inside the body.
I can't get it to hold the contents in the body.

<html><head>
<style type="text/css">
body {
text-align:center;
}
#container {
width:200px;
margin: 0 auto;
text-align:left;
border:solid 1px #000;
padding:5px;
}
</style>
<script type="text/javascript">
var d = document;
function insert(){
var box = d.createElement('div');
box.id = "container";
d.body.insertBefore(box, d.body.firstChild) // not what I want
// d.body.appendChild(box);
}
window.onload=insert;
</script>
</head>
<body>
This content should be centered and inside the div.
<h3>This text also.</h3>
</body>
</html>

Dec 20 '05 #1
1 4390
"aliensite" <al*******@excite.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I am trying to have a container div generated by the DOM, hold
everything inside the body.
I can't get it to hold the contents in the body.

<html><head>
<style type="text/css">
body {
text-align:center;
}
#container {
width:200px;
margin: 0 auto;
text-align:left;
border:solid 1px #000;
padding:5px;
}
</style>
<script type="text/javascript">
var d = document;
function insert(){
var box = d.createElement('div');
box.id = "container";
d.body.insertBefore(box, d.body.firstChild) // not what I want
// d.body.appendChild(box);
}
window.onload=insert;
</script>
</head>
<body>
This content should be centered and inside the div.
<h3>This text also.</h3>
</body>
</html>


That will create this:

<body>
<div id="container"></div>
This content should be centered and inside the div.
<h3>This text also.</h3>
</body>

What you need to do, is to grab the exsisting content of the body
as a node tree, delete it, create your container, add the grabbed
node tree to the container, and finally add the container to body

--
Dag.

Dec 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9869
by: CFW | last post by:
I use the following flawlessly to insert a single field: strSQL = "Insert into (Casket) Values " _ & "(" & conQuote & NewCasket & conQuote & ")" Set db = CurrentDb If MsgBox(NewCasket & " is...
5
7014
by: SSP | last post by:
Dear ASP.NETers, How would I insert multiple rows of data from a web form? Are there any tute's and stuff around. Couldn't find any myself. Thanks in advance. SSP
1
1664
by: tshad | last post by:
I can't seem to get insert into a DataGrid to work. I am using an example from the net and made changes to work on my computer. The grid comes up fine. The edit boxes in the footer are there. ...
1
4218
by: Tim H | last post by:
Is there an STL or similar container that behaves like a map (string keys or tempate<Tkeykeys with template<Tvalvalues) but can be iterated in insert order? I whipped up a keyed-vector as a...
6
9001
by: reppisch | last post by:
Hi Ng, I have a multiset for keeping elements sorted in a container but key values may also be equal. Is there any guaranteed traversal order within the duplicate keys of a multimap? When...
5
1797
by: pwalker | last post by:
Hi everyone, I am trying to get my head around iterators used on vectors. Let's take the code below: ------------- std::vector<intv1; std::vector<intv2; v1.push_back( 1 );
0
1160
by: subramanian100in | last post by:
Suppose I have a vector<Tor deque<Tfor some type T. Suppose vector<T>::iterator iter is an iterator. Then consider the operation vector<T>::iterator nit = container.insert(iter, T()); After...
2
162
by: Terry Reedy | last post by:
SUBHABRATA, I recommend you study this excellent response carefully. castironpi wrote: It starts with a concrete test case -- an 'executable problem statement'. To me, this is cleared and...
4
2382
by: Barno77 | last post by:
Everytime I edit a record, and hit update I get duplicating lines in my Details View. Here's my If statement: If (Len(e.OldValues("AutoNumber")) > 0) Then sql = "UPDATE SHIP_LOG SET...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5631
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.