Alert the outer HTML of a <h1> element:
Click the button to alert the outer HTML of the h1 element:
<!DOCTYPE html> <html> <body> <h1>Get outerHTML</h1> <p id="demo"></p> <button onclick="myFunction()">Alert Header</button> <script> function myFunction() {/*from w ww . j a va2 s . com*/ var x = document.getElementsByTagName("h1")[0]; document.getElementById("demo").innerHTML = x.outerHTML; } </script> </body> </html>