HTML DOM Anchor origin Property



The HTML DOM Anchor origin property returns the protocol, hostname and port number of the href attribute value, for example, https://www.demo.com:6064  

Following is the syntax−

anchorObj.origin

Let us now see an example to implement the DOM Anchor origin property −

Example

 Live Demo

<!DOCTYPE html>
    <html>
    <body>
    <h1>Company</h1>
    <p><a id="mylink" hreflang="en" href="http://www.abc.com:6064/abc/products.html">Products</a></p>
    <h2 id="myid"></h2>
    <button onclick="display()">Display href Part</button>
    <button onclick="display2()">Display origin</button>
    <button onclick="display3()">Display hreflang</button>
    <script>
    function display() {
       var a = document.getElementById("mylink").href;
          document.getElementById("myid").innerHTML = a;
       }
       function display2() {
          var a = document.getElementById("mylink").origin;
          document.getElementById("myid").innerHTML = a;
       }
       function display3() {
          var a = document.getElementById("mylink").hreflang;
          document.getElementById("myid").innerHTML = a;
       }
    </script>
    </body>
    </html>

Output

Click on the “Display origin” button−

Updated on: 2019-07-30T22:30:26+05:30

137 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements