HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <div> <h1>Heading</h1> <p>Paragraph</p> </div> <p>Click on the button to display the tagName of last child node inside div tag.</p> <button onclick="myFunction()">Click</button> <p id="point"></p> <script> var x = document.getElementById("point"); var node = document.getElementsByTagName("div")[0]; function myFunction(){ x.innerHTML = node.lastElementChild.tagName; } </script> </body> </html>
OUTPUT
×

Save as Private