Javascript examples for DOM HTML Element:Anchor
The username property sets or gets the username part of the href attribute value.
In the url of https://myUserName:password123@www.example.com, myUserName is the username and password123 is the password.
Set the username property with the following Values
Value | Description |
---|---|
username | Sets the username part of a URL |
A String, representing the username part of the URL
The following code shows how to Return the username part of a link:
<!DOCTYPE html> <html> <body> <p><a id="myAnchor" href="https://myUserName:password123@www.example.com">Example link</a></p> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w . j a v a2 s.co m var v = document.getElementById("myAnchor").username; document.getElementById("demo").innerHTML = v; } </script> </body> </html>