HTML DOM Anchor password Property

The HTML DOM Anchor password property set or return the password part of the href attribute value. The password part is entered by the user. If you want to display it, then it can be seen after the username and before the hostname i.e. https −//username −

Following is the syntax to set the password property −

anchorObj.password = password

Following is the syntax to return the password property −


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


 Live Demo

<!DOCTYPE html>
<p><a id="mylink" hreflang="en" href="https −//amit −">Products</a></p>
<h2 id="myid"></h2>
<button onclick="display()">Display password</button>
<button onclick="display2()">Display origin</button>
<button onclick="display3()">Display hreflang</button>
   function display() {
      var a = document.getElementById("mylink").password;
      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;


Click on the “Display password” button above to display the password −

Updated on: 30-Jul-2019


Kickstart Your Career

Get certified by completing the course

Get Started