Partager via


insertBefore method

Inserts an element into the document hierarchy as a child node of a parent object.

 

Syntax

IHTMLDOMNode retVal = object.insertBefore(newChild, refChild);

Parameters

  • newChild [in]
    Type: IHTMLDOMNode

    Pointer to an IHTMLDOMNode that specifies the new object to be inserted.

  • refChild [in, optional]
    Type: VARIANT

    VARIANT of type VT_DISPATCH or VT_UNKNOWN that specifies the placement of the new element. If this parameter is specified, the new element will be inserted immediately before this existing child element.

Standards information

Remarks

Do not specify the refChild parameter when inserting the first child node. If children already exist and you do not specify the refChild parameter, the newChild becomes the last child of the parent object.

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

Windows Internet Explorer 9. Exceptions are only supported when webpages are displayed in IE9 Standards mode.

Microsoft Internet Explorer 6 and later. The attribute object supports this method.

See also

About the W3C Document Object Model