/

HTML / CSS / JavaScript Tutorial

JavaScript DOM HTML method: insertBefore()

[this page | pdf | back links]

The insertBefore() method (when applied to HTML elements in the JavaScript DOM) inserts a new child node before an existing child node.

 

It has the following syntax with the following parameters. It returns a Node object representing the new child node.

 

element.insertBefore(newnode, existingnode)

 

Parameter

Required / Optional

Description

newnode

Required

The node object to be inserted

existingnode

Optional

The node object before which the new node is to be inserted. If not specified then the new node will be inserted at the end of the element

 


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile