JavaScript pare...LOGIN

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">点击这里获取父节点</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:

QQ截图20161013093529.png

Next Section
1
2
<!DOCTYPE HTML>
<html lang="en-US">
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
submitReset Code
ChapterCourseware