Skip to content
Related Articles

Related Articles

HTML DOM Node isConnected Property
  • Last Updated : 13 Aug, 2020

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:

  • true: If the node is connected to the document.
  • false: If the node is not connected to the document.

Example 1: This property returns false.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:



  • Before Clicking the Button:

  • After Clicking the Button:

Example 2: This property returns true.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

  • Before Clicking the Button:

  • After Clicking the Button:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :