HTML DOM insertAdjacentHTML() Method Last Updated : 13 Jun, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The DOM insertAdjacentHTML() method is used to insert a text as HTML file to a specified position. This method is used to change or add text as HTML. Syntax : node.insertAdjacentHTML(specify-position, text-to-enter) Return Value : This will return the page with the specified change. There are four legal position values that can be used. afterbeginafterendbeforebeginbeforeendPositionsEffectafterbegin :This will add text when the selected element just begin.afterend :This will add text when the selected element just end.beforebegin :This will add text when the selected element about to begin.beforeend :This will add text when the selected element about to end. Example-1: This is the example for the "afterbegin" position. html <!DOCTYPE html> <html> <head> <title> HTML | DOM insertAdjacentHTML() Method </title> <style> h1, h2 { color: green; text-align: center; } div { width: 80%; height: 240px; border: 2px solid green; padding: 10px; </style> </head> <body> <div> <h2>Welcome to</h2> <h1> <u>GeeksforGeeks.!</u> </h1> <h2 id="main"> HTML DOM insertAdjacentHTML() Method </h2> </div> <br> <button onclick="myFunction()">Click me.!</button> <script> function myFunction() { var h = document.getElementById("main"); h.insertAdjacentHTML("afterbegin", "<span style='color:green; " + "background-color: lightgrey; " + "width: 50%;'>This is Example of</span>"); } </script> </body> </html> Output : Before click on the button: After click on the button: Example-2: This is the example for the "afterend" position. html <!DOCTYPE html> <html> <head> <title> HTML | DOM insertAdjacentHTML() Method </title> <style> h1, h2 { color: green; text-align: center; } div { width: 80%; height: 240px; border: 2px solid green; padding: 10px; </style> </head> <body> <div> <h2>Welcome to</h2> <h1><u>GeeksforGeeks.!</u></h1> <h2 id="main"> This is Example of</h2> </div> <br> <button onclick="myFunction()">Click me.!</button> <script> function myFunction() { var h = document.getElementById("main"); h.insertAdjacentHTML("afterend", "<span style='color:green; " + "background-color: lightgrey;" + "font-size: 25px; " + "padding-left: 30px;" + "padding-right: 30px;" + "width: 50%;'>" + "HTML DOM insertAdjacentHTML() Method" + "</span>"); } </script> </body> </html> Output : Before click on the button: After click on the button: Note: Similarly "beforebegin" and "beforeend" can be used to add text in HTML. Supported Browsers: The browser supported by DOM insertAdjacentHTML() Method are listed below: Google Chrome 1.0Edge 17.0Internet Explorer 4.0Firefox 8.0Opera 8.0Safari 4.0 Comment More infoAdvertise with us Next Article HTML DOM Style maxWidth Property S ShivamKD Follow Improve Article Tags : JavaScript Technical Scripter 2018 Similar Reads HTML | DOM Style font Property The HTML DOM Style's font property is used to change the element's font properties. It can be used to change the font style, weight, size, and family. Syntax: To set the font style :node.style.font = "font-properties font-size font-family;"To get the current font style:node.style.font; Return Values 2 min read HTML | DOM Style lineHeight Property The Style lineHeight property is used for setting or returning the distance between lines in a text. It is a string which represents the distance between lines in the text. To return the line-height.object.style.lineHeightTo set the line-height.object.style.lineHeight = "normal|number|length|%|initi 2 min read HTML DOM Style maxWidth Property The maxWidth property of HTML DOM sets/returns the maximum width of an element. The maxWidth property affects only block-level elements, absolute or fixed position elements. Syntax: It returns the maxWidth property.object.style.maxWidthIt sets the maxWidth Property.object.style.maxWidth = "none | le 2 min read HTML | DOM AnimationEvent In the HTML document, AnimationEvent interface is used to represent events providing information related to animations. AnimationEvent contains properties such as animationName, elapsedTime and pseudoElement. animationName: The animationName property returns the name of the event animation. It retur 2 min read HTML | DOM Style animationFillMode Property The DOM style animationFillMode property is used to specify the style of an element when the animation is not playing or when an animation is finished or when there is a delay in animation. The animationFillMode property can override the default behavior of CSS animations by which CSS animations aff 3 min read HTML DOM ownerDocument Property The ownerDocument property returns the top-level document object of the node. Here, the owner document of the node is returned as the document object. It is a read-only property. Syntax: node.ownerDocument; Properties: nodeName property: It returns the name of the specified node. If the node is an e 2 min read HTML | DOM Style transitionDelay Property The transitionDelay property in HTML DOM is used to specify the time in seconds or milliseconds when execution of transition starts. The delay refers to the time, which to be waited before starting the transition effect. Syntax: It returns the transitionDelay property.object.style.transitionDelayIt 3 min read HTML DOM Style textDecorationStyle Property The Style textDecorationStyle property in HTML DOM is used to set the decoration of text with different kinds of lines. It can display the line in various styles like a single line, double line, wavy, etc. By using this property, we can display the line in a specified style. Syntax:Â Â It returns the 2 min read HTML | DOM Style listStyle Property The Style listStyle Property in HTML DOM used to set up to three list properties namely list-style-typelist-style-positionlist-style-image Syntax: It returns the listStyle property.object.style.listStyleIt used to set the listStyle property.object.style.listStyle = "type position image|initial|inher 2 min read HTML | DOM Style outlineStyle Property The Style outlineStyle property in HTML DOM is used to set or return the style of the outline around an element. Syntax: It is used to return the outlineStyle property.object.style.outlineStyleIt is used to set the outlineStyle property.object.style.outlineStyle = value Property Values: none: This i 2 min read Like