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:

new file
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>HTML DOM树型结构图</title>
<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>
</head>
<body>
</body>
</html>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















