Definition and Usage parentNode..
The parentNode property returns the parent node of the specified node, as a Node object.
Note: In HTML, the document itself is the parent node of the HTML element, HEAD and BODY are child nodes of the HTML element.
This property is read-only.
Return Value:A Node object, representing the parent node of a node, or null if the node has no parent
Syntax: node.parentNode
Definition and Usage parentElement..
The parentElement property returns the parent element of the specified element.
The difference between parentElement and parentNode, is that parentElement returns null if the parent node is not an element node.
In most cases, it does not matter which property you use, however, parentNode is probably the most popular.
This property is read-only.
Return Value: An Element object, representing the parent element node of a node, or null if the node has no parent
Syntax: node.parentElement
Differents way how to declare parentElement and parentElement in program.
CODING:The parentNode property returns the parent node of the specified node, as a Node object.
Note: In HTML, the document itself is the parent node of the HTML element, HEAD and BODY are child nodes of the HTML element.
This property is read-only.
Return Value:A Node object, representing the parent node of a node, or null if the node has no parent
Syntax: node.parentNode
Definition and Usage parentElement..
The parentElement property returns the parent element of the specified element.
The difference between parentElement and parentNode, is that parentElement returns null if the parent node is not an element node.
In most cases, it does not matter which property you use, however, parentNode is probably the most popular.
This property is read-only.
Return Value: An Element object, representing the parent element node of a node, or null if the node has no parent
Syntax: node.parentElement
Differents way how to declare parentElement and parentElement in program.
<!DOCTYPE html>
<html>
<body>
<ul>
<li id="LI">JAVA</li>
<li>PYTHON</li>
<button onclick="this.parentNode.style.display = 'none';">Close</button>
</ul>
<button onclick="myFunction()">Parent Tag Name</button>
<script>
function myFunction() {
var x = document.getElementById("LI");
document.getElementById("demo").innerHTML = x.parentNode.nodeName;
//also declare x.parentElement.nodeName
}
</script>
</body>
</html>
<html>
<body>
<ul>
<li id="LI">JAVA</li>
<li>PYTHON</li>
<button onclick="this.parentNode.style.display = 'none';">Close</button>
</ul>
<button onclick="myFunction()">Parent Tag Name</button>
<script>
function myFunction() {
var x = document.getElementById("LI");
document.getElementById("demo").innerHTML = x.parentNode.nodeName;
//also declare x.parentElement.nodeName
}
</script>
</body>
</html>
Comments
Post a Comment