HTML DOM Anchor pathname Property

The HTML DOM Anchor pathname property is used to set or return the path name of the href attribute.

Following is the syntax to set the pathname property −

anchorObj.pathname = path

Above, path is the pathname of the URL.

Following is the syntax to return the pathname property −


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


 Live Demo

<!DOCTYPE html>
<p><a id="mylink" hreflang="en" href="https −//">Products</a></p>
<h2 id="myid"></h2>
<button onclick="display1()">Display pathname</button>
<button onclick="display2()">Display hreflang</button>
   function display1() {
      var a = document.getElementById("mylink").pathname;
      document.getElementById("myid").innerHTML = a;
   function display2() {
      var a = document.getElementById("mylink").hreflang;
      document.getElementById("myid").innerHTML = a;


Above, click on “Display pathname” to display the path part −