Open In App

HTML | DOM Link rel Property

The HTML | DOM Link rel Property in HTML DOM is used to set or return the value of the rel attribute of a linked document. The rel attribute is used to specify the relation between the current document and the linked document.

Syntax:  



linkObject.rel
linkObject.rel = relationship

Property Values:  

Return value : It returns a  string value, which representing a space-separated list of relationship types



Example-1: This Example returns a rel Property. 




<!DOCTYPE html>
<html>
<head>
    <link id="linkid"
          rel="stylesheet"
          type="text/css"
          href="styles.css"
          sizes="16*16">
</head>
 
<body style="text-align:center;">
    <h1>GeeksForGeeks</h1>
    <h2>DOM Link rel Property</h2>
    <button onclick="gfg()">Get URL
    </button>
    <p id="pid"
       style="font-size:25px;
              color:green;">
      </p>
 
    <script>
        function gfg() {
 
            // Return  Link rel Property
            var NEW = document.getElementById(
                "linkid").rel;
            document.getElementById(
                "pid").innerHTML = NEW;
        }
    </script>
</body>
</html>

Output: 
Before Clicking On Button : 

After Clicking On Button : 

Example-2: This Example sets the rel Property. 




<!DOCTYPE html>
<html>
<head>
    <link id="linkid"
          rel="stylesheet"
          type="text/css"
          href="styles.css"
          sizes="16*16">
</head>
 
<body style="text-align:center;">
    <h1>GeeksForGeeks</h1>
    <h2>DOM Link rel Property</h2>
    <button onclick="gfg()">Get URL
    </button>
    <p id="pid"
       style="font-size:25px;
              color:green;">
      </p>
 
    <script>
        function gfg() {
 
            // Set  Link rel Property
            var NEW = document.getElementById(
                "linkid").rel = "alternate";
            document.getElementById(
                "pid").innerHTML =
        "The value of the rel attribute was changed to "
            + NEW;
        }
    </script>
</body>
</html>

Output : 
Before Clicking On Button: 

After Clicking On Button: 

Supported Browsers: 


Article Tags :