JavaScript parentNode: Get the parent node
Syntax:
nodeObject.parentNode
Among them, nodeObject is the node object (element node).
For example, get the parent node of the node with id="demo":
document.getElementById("demo").parentNode;
For example, get the id="demo" "The parent node of the node:
<div> <div id="demo">點擊這里獲取父節(jié)點</div> </div> <script type="text/javascript"> document.getElementById("demo").onclick=function(){ var demoParent=this.parentNode; alert( "父節(jié)點的名稱是:"+demoParent.nodeName+"\n"+ "父節(jié)點的類型是:"+demoParent.nodeType ); } </script>
Please see the following demonstration: