Open In App

HTML DOM Anchor host Property

Improve
Improve
Like Article
Like
Save
Share
Report

The DOM Anchor host Property in HTML DOM is used to set or return the hostname and post part of the href attribute value.

Syntax:

  • It returns the host property.
    anchorObject.host
  • It is used to set the host property.
    anchorObject.host = hostname:port

Property Values: It contains the value hostname:port Which specify the hostname and the port number of a URL.

Return Value: It returns a string value which represents the domain name and the port number of the URL.

Example: This example returns the host Property.

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Anchor host Property
    </title>
</head>
 
<body style="text-align: center;">
    <h1>GeeksforGeeks</h1>
 
    <h2>
        DOM Anchor host Property
    </h2>
 
    <p>Welcome to
        <a href="https://www.geeksforgeeks.org:5000"
            id="GFG">
            GeeksforGeeks
        </a>
    </p>
 
    <button onclick="myGeeks()">
        Submit
    </button>
 
    <p id="sudo"></p>
 
    <script>
        function myGeeks() {
            let x = document.getElementById("GFG").host;
            document.getElementById("sudo").innerHTML = x;
        }
    </script>
</body>
 
</html>


Output:

anchor-host

Example 2: This example sets the Host Property.

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Anchor host Property
    </title>
</head>
 
<body style="text-align: center;">
    <h1>GeeksforGeeks</h1>
 
    <h2>
        DOM Anchor host Property
    </h2>
 
    <p>Welcome to
        <a href="https://ide.geeksforgeeks.org:5000/"
            id="GFG">
            GeeksforGeeks
        </a>
    </p>
 
    <button onclick="myGeeks()">
        Submit
    </button>
 
    <p id="sudo"></p>
 
    <script>
        function myGeeks() {
            let x = document.getElementById("GFG").host
                = "www.geeksforgeeks.org:5500";
 
            document.getElementById("sudo").innerHTML = x;
        }
    </script>
</body>
 
</html>


Output:

anchor-host-2

Supported Browsers:

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


Last Updated : 02 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads