编辑下面的代码:【加编码】
<html> <body> <p>Example list:</p> <ul><li>Coffee</li><li>Tea</li></ul> <p id="demo">Click the button get the node name of the parent node of the first list item in a list</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { var x=document.getElementById("demo"); var y=document.getElementsByTagName("LI")[0]; x.innerHTML=y.parentNode.nodeName; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂