JavaScript node.contains() Method
You are Here:
JavaScript node.contains() Method
The node.contains()
method indicates whether a node is a descendant of a specified node.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<p><span>span</span> inside paragraph</p>
<button onclick="myFunction()">Click Me</button>
<script>
var p = document.getElementsByTagName("p")[0];
var span = document.getElementsByTagName("span")[0];
function myFunction(){
alert(p.contains(span));
}
</script>
</body>
</html>
Syntax
node.contains(otherNode)
Parameter Values
Value | Type | Explanation |
---|---|---|
otherNode | Required | A node to check whether it is a descendant of a given node. |
Return Values
Value | Explanation |
---|---|
true | If the otherNode is a descendant of a given node. |
false | If the otherNode is not a descendant of a given node. |
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.