HTML DOM insertBefore() Method Last Updated : 13 Jun, 2023 Comments Improve Suggest changes Like Article Like Report The insertBefore() method in HTML DOM is used to insert a new node before the existing node as specified by the user. Syntax: node.insertBefore( newnode, existingnode ) Parameters: This method accepts two parameters as mentioned above and described below: newnode: It is the required parameter. This parameter contains the new node object which need to insert.existingnode: It is the required parameter. It describes the position where new node insert before this node. If it set to null then insertBefore method will insert the new node at the end. Return Value: It returns the node object which represent the inserted node. Example: In this example, insert a list element before the second node of the list. html <!DOCTYPE html> <html> <head> <title> HTML | DOM insertBefore() Method </title> <!--Script to insert a new node before existing node--> <script> function myGeeks() { var newItem = document.createElement("li"); var textnode = document.createTextNode("Java"); newItem.appendChild(textnode); var list = document.getElementById("subjects"); list.insertBefore(newItem, list.childNodes[2]); } </script> </head> <body> <h1> Welcome To GeeksforGeeks </h1> <h2> HTML DOM insertBefore() Method </h2> <ul id="subjects"> <li>C++</li> <li>Python</li> </ul> <p> Click on the button to insert an element before Python </p> <button onclick="myGeeks()"> Insert Node </button> </body> </html> Output: Before Click on the button: After Click on the button: Supported Browsers: The browser supported by DOM insertBefore() Method are listed below: Google Chrome 1 and aboveEdge 12 and aboveInternet Explorer 6 and aboveFirefox 1 and aboveOpera 7 and aboveSafari 1.1 and above Comment More infoAdvertise with us P ProgrammerAnvesh Follow Improve Article Tags : Web Technologies HTML HTML-DOM Similar Reads HTML DOM insertAdjacentText() Method The insertAdjacentText() inserts a provided text at one of the following positions. afterbegin:afterend:beforebegin:beforeend: Syntax: node.insertAdjacentText(position, text) Parameters: This method requires 2 parameters. position: A position relative to the element. The legal values are:afterbegin: 1 min read HTML DOM Style borderImage Property The DOM Style borderImage Property in HTML is a shorthand property used for setting the borderImageSource, borderImageSlice, borderImageWidth,borderImageOutset, and borderImageRepeat properties. Syntax: It is used to return the borderImage property. object.style.borderImageIt is used to set the bord 2 min read HTML DOM stopPropagation() Event Method The stopPropagation() method is used to stop the propagation of event calling. That is a parent event is called we can stop the propagation of calling its children by using the stopPropagation() method and vice-versa. Syntax: event.stopPropagation() Return Value: It does not return any value. Exampl 2 min read HTML DOM Emphasized Object The HTML DOM Emphasized object represents the <em> element, used to emphasize text, typically rendering it in italics. It can be accessed and manipulated through JavaScript to alter its content or styling.Syntax:document.getElementById("ID");Example: Clicking the "Submit" button changes the em 1 min read HTML DOM type Event Property The type event property in HTML DOM is used to return the type of the triggered event. It returns a string that represents the type of the event. The events can be keyboard events or mouse events. Syntax: event.type Return Value: It returns a string that represents the type of event. Example: In thi 1 min read HTML DOM timeStamp Event Property The timeStamp property in the HTML DOM refers to a read-only property that returns the time (in milliseconds) at which an event was created. The value is measured relative to the UNIX epoch (January 1, 1970, 00:00:00 UTC). This property is commonly used to determine the timing of events and can be u 1 min read HTML | DOM Details Object The DOM Details Object is used to represent the HTML <details> element. The Details element is accessed by getElementById(). Properties: open: The details tag has an attribute called 'open' which is used to display the hidden information by default. Syntax: document.getElementById("ID"); Where 2 min read HTML DOM cancelable Event Property The cancelable event property indicates whether the event's default action can be prevented. If the value is true, the default action can be prevented using event.preventDefault(). If false, the default action cannot be prevented. It is a read-only property.It is a read-only boolean property.Syntax: 1 min read HTML DOM Style borderImageRepeat Property The borderImageRepeat style property in HTML DOM is used to set or return the borderImageRepeat property. It specifies whether the border image should repeat to fill the area, stretched to fill the area, set to the initial value, inherit property from its parent, etc. Depending on the need it will b 4 min read HTML | DOM Style borderImageOutset Property In the Style borderImageOutset Space which contains the border, image is to be painted is called the border-image space. By default, the boundaries of the border image area match with the boundaries of the elementâs border-box. However, these boundaries can be extended using the border-image-outset 4 min read Like