appendChild method
[This documentation is preliminary and is subject to change.]
Appends an element as a child to the object.
![]() |
Syntax
object.appendChild(newChild)Standards information
Parameters
- newChild [in]
-
Type: IHTMLDOMNode
Object that specifies the element to append.
Return value
Type: ObjectReturns 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.
Windows Internet Explorer 9. Exceptions are only supported when webpages are displayed in IE9 Standards mode.
In Microsoft Internet Explorer 6, This method now applies to the attribute object.
Examples
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>
<li>List node 2</li>
<li>List node 3</li>
<li>List node 4</li>
</ul>
<input
type = "button"
value = "Append Child"
onclick = "fnAppend()" />
</body>
See also
- a
- abbr
- acronym
- address
- attribute
- article
- aside
- b
- bdo
- big
- blockQuote
- body
- button
- caption
- center
- cite
- code
- col
- colGroup
- comment
- dd
- del
- dfn
- dir
- div
- dl
- dt
- documentType
- em
- figcaption
- figure
- fieldSet
- font
- footer
- form
- frameSet
- head
- header
- hgroup
- 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
- mark
- marquee
- menu
- nav
- nextID
- ol
- option
- p
- plainText
- pre
- ProcessingInstruction
- q
- s
- samp
- section
- small
- span
- strike
- strong
- sub
- sup
- table
- tBody
- td
- textArea
- tFoot
- th
- tHead
- tr
- tt
- u
- ul
- var
- xmp
- Reference
- cloneNode
- insertBefore
- Conceptual
- About the W3C Document Object Model
Build date: 2/14/2012
d.getElementsByTagName('body')[0].appendChild(d.createElement('div')
- 1/15/2012
- tnesham
- 11/18/2011
- YannickVA
- 8/4/2010
- Personperson33
Any tips?
- 5/9/2008
- SharkD
