From: "Philipp Lenssen" <phil@mrinfo.de>
Newsgroups: comp.infosystems.www.authoring.html
Subject: Re: appending elements to html document
Date: Thu, 15 Nov 2001 09:48:32 +0100
Message-ID: <9svvet$efj$1@swifty.westend.com>
Newsgroups: comp.infosystems.www.authoring.html
Subject: Re: appending elements to html document
Date: Thu, 15 Nov 2001 09:48:32 +0100
Message-ID: <9svvet$efj$1@swifty.westend.com>
"Riyaz Mansoor" <s800032@student.uq.edu.au> wrote in message
news:9svreo$nnh$1@bunyip.cc.uq.edu.au...
>..
> how can i append an element to the current point in the html doucment?
>
> <body>
> <script>
> element = document.createElement('div');
> document.appendChild(element); // does not work.
> </script>
> </body>
>
> the actual object i'm appending is a complex 'div' element and i'd rather
> keep it separate in a javascript file.
>..
This is more a question for a scripting newsgroup, but try the following.
(Tested in IE6/ Netscape 6.)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>
<script type="text/javascript">
function addElement()
{
var divElement;
var divParent;
var divText;
divElement = document.createElement("div");
divText = document.createTextNode("Hello World");
divParent = document.getElementById("divParent");
divElement.appendChild(divText);
divParent.appendChild(divElement);
}
</script>
</head>
<body id="divParent" onload="addElement()">
</body>
</html>
--
Philipp Lenssen
M+R Infosysteme
http://www.mrinfo.de
