HTML DOM insertAdjacentElement() Method Last Updated : 13 Jun, 2023 Comments Improve Suggest changes Like Article Like Report The insertAdjacentElement() method inserts the specified element at the specified position. The legal values for this position are. afterbeginafterendbeforebeginbeforeend Syntax: node.insertAdjacentElement(position, element) Parameters: This method requires 2 parameters. position: A position relative to the element. The legal values are :-afterbegin: Just inside the element, before its first child.afterend: After the element itself.beforebegin: Before the element itself.beforeend: Just inside the element, after its last child.element: The element you want to insert. Return Value: The element that was inserted, or null, if the insertion failed. Exceptions: If the specified position is not recognized or if the specified element is not a valid element. Example: HTML <!DOCTYPE html> <html> <head> <!--script to insert specified element to the specified position--> <script> function insadjele() { var s = document.getElementById("d1"); var h = document.getElementById("head3"); h.insertAdjacentElement("afterend", s); } </script> </head> <body> <h1> Welcome To GeeksforGeeks</h1> <div id="d1">div element</div> <h3 id="head3">header element</h3> <p>Click the button to insert div element after the header element</p> <button onclick="insadjele()">Insert element</button> </body> </html> Output: Before clicking insert element button: After clicking insert element button: Supported Browsers: The browser supported by DOM insertAdjacentElement() Method are listed below: Google Chrome 1 and aboveEdge 17 and aboveFirefox 48 and aboveOpera 8 and aboveInternet Explorer 5 and aboveSafari 3 and above Create Quiz Comment P ProgrammerAnvesh Follow 0 Improve P ProgrammerAnvesh Follow 0 Improve Article Tags : Web Technologies HTML HTML-DOM HTML-Methods Explore HTML BasicsHTML Introduction4 min readHTML Editors4 min readHTML Basics7 min readStructure & ElementsHTML Elements4 min readHTML Attributes7 min readHTML Headings3 min readHTML Paragraphs3 min readHTML Text Formatting4 min readHTML Block and Inline Elements3 min readHTML Charsets4 min readListsHTML Lists3 min readHTML Ordered Lists5 min readHTML Unordered Lists4 min readHTML Description Lists3 min readVisuals & MediaHTML Colors11 min readHTML Links Hyperlinks2 min readHTML Images7 min readHTML Favicon4 min readHTML Video4 min readLayouts & DesignsHTML Tables10 min readHTML Iframes4 min readHTML Layout4 min readHTML File Paths3 min readProjects & Advanced TopicsHTML Forms5 min readHTML5 Semantics5 min readHTML URL Encoding4 min readHTML Responsive Web Design11 min readTop 10 Projects For Beginners To Practice HTML and CSS Skills8 min readTutorial ReferencesHTML Tags - A to Z List15+ min readHTML Attributes Complete Reference8 min readHTML Global Attributes5 min readHTML5 Complete Reference8 min readHTML5 MathML Complete Reference3 min readHTML DOM Complete Reference15+ min readHTML DOM Audio/Video Complete Reference2 min readSVG Element Complete Reference5 min readSVG Attribute Complete Reference8 min readSVG Property Complete Reference7 min readHTML Canvas Complete Reference4 min read Like