inserts a new node into the specified position

void insertBefore(HTMLElement node,HTMLElement before, [HTMLElement rescue] );
nodeHTMLElementa new DOM node
beforeHTMLElementthe sibling node that the new node will be inserted before
rescueHTMLElementthe parent node used if the subling doesn't exist


var newdiv=document.createElement("div");


The method inserts a new node before the specified sibling (the before parameter) or as the last child of the specified parent (the rescue parameter) if the sibling doesn't exist.
The third parameter is optional and used just to avoid errors in case the specified subling doesn't exist.

See also
Back to top