insertAdjacentElement method (Internet Explorer)

Switch View :
ScriptFree
insertAdjacentElement method

[This documentation is preliminary and is subject to change.]

Inserts an element at the specified location.

Syntax

object.insertAdjacentElement(where, insertedElement)

Standards information

There are no standards that apply here.

Parameters

where [in]

Type: BSTR

A String that specifies where to insert the HTML element, using one of the following values.

beforeBegin

Inserts insertedElement immediately before the object.

afterBegin

Inserts insertedElement after the start of the object, but before all other content in the object.

beforeEnd

Inserts insertedElement immediately before the end of the object, but after all other content in the object.

afterEnd

Inserts insertedElement immediately after the end of the object.

insertedElement [in]

Type: IHTMLElement

Object that specifies the element to be inserted adjacent to the object that invoked the insertAdjacentElement method.

Return value

Type: ObjectReturns an element object.

Remarks

You cannot insert text while the document is loading. Wait for the onload event before attempting to call this method.

If you try to insert an object that already exists on the page, the existing object is moved to the point that you specified in the insertAdjacentElement method; no new object is created.

Examples

This example uses the insertAdjacentElement method to add a new list item to an ol object.


<SCRIPT>
function fnAdd()
{
   var oNewItem = document.createElement("LI");	
   oList.children(0).insertAdjacentElement("BeforeBegin",oNewItem);
   oNewItem.innerText = "List Item 0";
}
</SCRIPT>
:
<BODY>
<OL ID = "oList">
<LI>List Item 1</LI>
<LI>List Item 2</LI>
<LI>List Item 3</LI>
</OL>
<INPUT TYPE = "button" VALUE = "Add Item" onclick="fnAdd()">
</BODY>

 

 

Build date: 2/14/2012