Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with creating a DIV using appendChild

Status
Not open for further replies.

econnections

IS-IT--Management
Apr 28, 2006
30
GB
Hello,

Is it possible to append a DIV or SPAN to an existing document using the appendChild command? And if so how would I do this?

Thanks
Graham
 
With a little help from another forum I found a way to add a new element to a document using a javascript function and then hide the element (DIV) with another function. I share the code as it may be helpful for other users:



<html>
<head>
<script type="text/javascript">

function createDIV() {
t = document.createTextNode ('Fee, fie, foe and fum.')
p = document.createElement ("<div id='x'></div>")
p.appendChild (t)
body = document.getElementsByTagName ('BODY')[0]
body.appendChild (p)
}

function hideDIV() {
document.getElementById('x').style.display = 'none';

}

</script>

</head>
<body>
<form name="form1" method="post" action="">
<input type="button" name="Button" value="Create DIV" onclick="createDIV()">
<input type="button" name="Button" value="Hide DIV" onclick="hideDIV()">
</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top