HTMLAnchorElement: username property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
Theusername property of theHTMLAnchorElement interface is a string containing the username component of the<a> element'shref. If the URL does not have a username, this property contains an empty string,"".
This property can be set to change the username of the URL. If the URL has nohost or its scheme isfile:, then setting this property has no effect.
The username ispercent-encoded when setting but not percent-decoded when reading.
SeeURL.username for more information.
In this article
Value
A string.
Examples
>Getting the username from an anchor link
js
// An <a href="https://anonymous:flabada@developer.mozilla.org/en-US/docs/HTMLAnchorElement"> element is in the documentconst anchor = document.getElementByID("myAnchor");anchor.username; // returns 'anonymous'Specifications
| Specification |
|---|
| HTML> # dom-hyperlink-username-dev> |
Browser compatibility
See also
- The
HTMLAnchorElementinterface it belongs to.