HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h2>Heading</h2> <p>Click on the button to insert the span after the beginning of the h2 tag.</p> <button onclick="myFunction()">Click Me</button> <script> var target = document.getElementsByTagName("h2")[0]; var text = '<span style="color:blue;">Span</span>'; function myFunction(){ target.insertAdjacentHTML("afterbegin", text); } </script> </body> </html>
OUTPUT
×

Save as Private