appendChild Method

DHTML, HTML, & CSS

 
Click to return to the DHTML, HTML & CSS home page    
alert Method     applyElement Method     DHTML Methods    

appendChild Method


Appends an element as a child to the object.

Syntax

oElement = object.appendChild(oNode)

Parameters

oNodeRequired. Object that specifies the element to append.

Return Value

Returns a reference to the element that is appended to the object.

Remarks

The appendChild method appends elements to the end of the childNodes collection.

To display new elements on the page, you must append them within the BODY element. For example, the following syntax demonstrates how to add a DIV element to the BODY.

var oDiv=document.createElement("DIV");
document.body.appendChild(oDiv);

This method is accessible at run time. If elements are removed at run time, before the closing tag is parsed, areas of the document might not render.

Example

This example uses the appendChild method to add an item to an unordered list.

<SCRIPT>
function fnAppend(){
   var oNewNode = document.createElement("LI");
   oList.appendChild(oNewNode);
   oNewNode.innerText="List node 5";
}
</SCRIPT>
<BODY>
<UL ID = oList>
<LI>List node 1
<LI>List node 2
<LI>List node 3
<LI>List node 4
</UL>

<INPUT
   TYPE = "button"
   VALUE = "Append Child"
   onclick = "fnAppend()">
</BODY>

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
A, ACRONYM, ADDRESS, B, BDO, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, COMMENT, DD, DEL, DFN, DIR, DIV, DL, DT, EM, FIELDSET, FONT, FORM, FRAMESET, HEAD, Hn, HTML, I, IFRAME, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, INS, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, NEXTID, OL, OPTION, P, PLAINTEXT, PRE, Q, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP

See Also

cloneNode, insertBefore


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.