HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h2>Heading</h2> <span style="color:blue;">Span</span> <p>Click on the button to replace the span after the end of the h2 tag.</p> <button onclick="myFunction()">Click Me</button> <p><strong>Note</strong>: span tag is already placed afterend of h2 tag.</p> <script> var target = document.getElementsByTagName("h2")[0]; var elem = document.getElementsByTagName("span")[0]; function myFunction(){ target.insertAdjacentElement("afterend", elem); } </script> </body> </html>
OUTPUT
×

Save as Private