Open In App

HTML DOM Node isConnected Property

The isConnected property returns a boolean value indicating whether the node is connected (directly or indirectly) to the context object or the document. This is a read-only property.

Syntax:



check = node.isConnected

Return Value:

Example 1: This property returns false.






<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <title>HTML DOM Node isConnected property</title>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
 
     
<p>Click to Check</p>
 
 
    <button onclick="Check()">Click</button>
 
    <script>
        function Check() {
            let exp = document.createElement('p');
            exp.innerHTML = "abcd";
            a = exp.isConnected;
            console.log(a); // Returns false
            if (a == false) {
                console.log("Not Connected");
            }
            else {
                console.log("Connected")
            }
        }
    </script>
</body>
 
</html>

Output:

Before Clicking the Button:

After Clicking the Button:

Example 2: This property returns true.




<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <title>HTML DOM Node isConnected property</title>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
 
     
<p>Click to Check</p>
 
 
    <button onclick="Check()">Click</button>
 
    <script>
        function Check() {
            let exp = document.createElement('p');
            exp.innerHTML = "abcd";
            document.body.appendChild(exp);
            a = exp.isConnected;
            console.log(a); // Returns true
            if (a == false) {
                console.log("Not Connected");
            }
            else {
                console.log("Connected")
            }
        }
    </script>
</body>
 
</html>

Output:

Before Clicking the Button:

After Clicking the Button:

Supported Browsers:


Article Tags :