Anchor username attribute

Definition and usage

username Attribute setting or return href attribute value The username part.

In the URL, the username part is the username entered by the user. It is specified between the protocol and the password part.

For example: https://billgates:bill234@www.example.com (billgates is the username, bill234 is the password).

Tip:Please use password attribute Set or return href attribute value The password part.

Example

Example 1

Return the username part of the link:

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

Try it yourself

Example 2

Change the username part of the link:

document.getElementById("myAnchor").username = "newUsername";

Try it yourself

Syntax

Return the username attribute:

anchorObject.username

Set username attribute:

anchorObject.username = username

Attribute Value

Value Description
username Specifies the username part of the URL.

Technical Details

Return Value: A string value representing the username part of the URL.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Supported Not Supported Supported Not Supported Supported