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">点击这里获取父节点</div>
</div>
<script type="text/javascript">
document.getElementById("demo").onclick=function(){
var demoParent=this.parentNode;
alert(
"父节点的名称是:"+demoParent.nodeName+"\n"+
"父节点的类型是:"+demoParent.nodeType
);
}
</script>Please see the following demonstration:
