Click to return to the DHTML, HTML     
inRange Method     insertAdjacentHTML Method     DHTML Methods    
Web Workshop  |  DHTML, HTML & CSS

insertAdjacentElement Method


Inserts an element at the specified location.

Syntax

oElement = object.insertAdjacentElement(sWhere, oElement)

Parameters

sWhereRequired. String that specifies where to insert the HTML text, using one of the following values:
beforeBeginInserts oElement immediately before the object.
afterBeginInserts oElement after the start of the object but before all other content in the object.
beforeEndInserts oElement immediately before the end of the object but after all other content in the object.
afterEndInserts oElement immediately after the end of the object.
oElementRequired. Object that specifies the element to be inserted adjacent to the object that invoked the insertAdjacentElement method.

Return Value

Returns an element object.

Remarks

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 insertAdjacentElement method to add a new list item to an OL object.

<SCRIPT> function fnAdd(){ var oNewItem = document.createElement("LI"); oList.children(0).insertAdjacentElement("AfterBegin",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>

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
A, ACRONYM, ADDRESS, APPLET, AREA, B, BASE, BASEFONT, BDO, BGSOUND, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, COMMENT, DD, DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, FRAMESET, HEAD, Hn, HR, HTML, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, INS, KBD, LABEL, LEGEND, LI, LINK, LISTING, MAP, MARQUEE, MENU, NEXTID, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, Q, S, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TITLE, TR, TT, U, UL, VAR, XMP


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.