Open In App
Related Articles

HTML DOM Area href Property

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The Area href Property in HTML DOM is used to set or return the value of the href attribute. It is used to specify the URL of the area. 

For example: https://manaschhabra:manaschhabra499@www.geeksforgeeks.org/ (manaschhabra is the username and manaschhabra499 is the password). 

Syntax:

  • It returns the href property.
 areaObject.href
  • It is used to set the href property.
areaObject.href = URL

Property Values: It contains a single value href which specifies the URL. It can be an absolute URl, a relative URL, a link to an element, etc.

Three Possible Values :

  • absolute URL: It points to another website.
  • relative URL: It points to a file within a website.
  • anchor URL: It points to an anchor within a page.

 Return Value: It returns a string value that represents the URL. 

Example 1: This example returns the Area href Property. 

HTML

<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Area href Property
    </title>
</head>
 
<body>
    <h4>HTML DOM Area href Property</h4>
    <button onclick="GFG()">
          Click Here!
    </button>
    <map name="Geeks1">
        <area id="Geeks" shape="rect"
              coords="0, 0, 110, 100"
              alt="Geeks"
              href=
    </map>
    <img src=
         width="300" height="100"
         alt="Geeksforgeeks"
         usemap="#Geeks1">
    <br>
    <p id="GEEK!"></p>
 
    <script>
        function GFG() {
            // Return value of href attribute.
            let x = document.getElementById("Geeks").href;
            document.getElementById("GEEK!").innerHTML = x;
        }
    </script>
</body>
</html>

                    

Output: 

 

Example 2: This example sets the Area href property. 

HTML

<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Area href Property
    </title>
</head>
 
<body>
    <h4>HTML DOM Area href Property</h4>
    <button onclick="GFG()">
          Click Here!
    </button>
    <map name="Geeks1">
        <area id="Geeks" shape="rect"
              coords="0, 0, 110, 100"
              alt="Geeks"
              href=
    </map>
 
    <img src=
         width="300" height="100"
         alt="Geeksforgeeks"
         usemap="#Geeks1">
    <br>
    <p id="GEEK!"></p>
 
    <script>
        function GFG() {
 
            // Sets href property.
            let x = document.getElementById("Geeks").href =
                "https://abc:abc499@www.geeksforgeeks.org/";
                document.getElementById("GEEK!").innerHTML =
                    "The href has been changed to " + x;
        }
    </script>
</body>
</html>

                    

Output:

 

Supported Browsers:

  • Google Chrome
  • Firefox
  • Internet Explorer
  • Opera
  • Safari


Last Updated : 23 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads