HTMLAnchorElement: port property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Theport property of theHTMLAnchorElement interface is a string containing the port number of the<a> element'shref. If the port is the default for the protocol (80 forws: andhttp:,443 forwss: andhttps:, and21 forftp:), this property contains an empty string,"".
This property can be set to change the port of the URL. If the URL has nohost or its scheme isfile:, then setting this property has no effect. It also silently ignores invalid port numbers.
SeeURL.port for more information.
In this article
Value
A string.
Examples
>Getting the port from an anchor link
js
// An <a href="https://developer.mozilla.org:443/en-US/docs/HTMLAnchorElement"> element is in the documentconst anchor = document.getElementByID("myAnchor");anchor.port; // returns ''js
// Another <a href="https://developer.mozilla.org:8888/en-US/docs/HTMLAnchorElement"> element is in the documentconst anchor = document.getElementByID("myAnchor");anchor.port; // Returns:'8888'Specifications
| Specification |
|---|
| HTML> # dom-hyperlink-port-dev> |
Browser compatibility
See also
- The
HTMLAnchorElementinterface it belongs to.