Javascript DOM HTML Anchor username Property get

Introduction

The username property sets or gets the user name part of the href attribute value.

Return the username part of a link:

var x = document.getElementById("myAnchor").username;

Click the button to display the username part of the link.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p><a id="myAnchor" href="https://userName:password123@www.java2s.com">Example link</a></p>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from  ww  w.j ava  2 s  .  c o m
  var x = document.getElementById("myAnchor").username;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related