HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <div>Div 1</div> <h1>Heading 1</h1> <p>Paragraph 1</p> <p>Click the button to find the previousSibling of h1 tag.</p> <button onclick="myFunction()">Click Me</button> <p id="point"></p> <script> var x = document.getElementById("point"); var y = document.getElementsByTagName("h1")[0]; function myFunction(){ //Try to replace "previousSibling" by "previousSibling.previousSibling" x.innerHTML = y.previousSibling.nodeName; } </script> <p><strong>Note</strong>: The previousSibling include tags and texts.</p> </body> </html>
OUTPUT
×

Save as Private