Baseline Widely available
The port
property of the HTMLAnchorElement
interface is a string containing the port number of the <a>
element's href
. If the port is the default for the protocol (80
for ws:
and http:
, 443
for wss:
and https:
, and 21
for ftp:
), this property contains an empty string, ""
.
This property can be set to change the port of the URL. If the URL has no host
or its scheme is file:
, then setting this property has no effect. It also silently ignores invalid port numbers.
See URL.port
for more information.
A string.
Examples Getting the port from an anchor link// An <a id="myAnchor" href="https://developer.mozilla.org:443/en-US/docs/HTMLAnchorElement"> element is in the document
const anchor = document.getElementByID("myAnchor");
anchor.port; // returns ''
// Another <a id="myAnchor" href="https://developer.mozilla.org:8888/en-US/docs/HTMLAnchorElement"> element is in the document
const anchor = document.getElementByID("myAnchor");
anchor.port; // Returns:'8888'
Specifications Browser compatibility See also
HTMLAnchorElement
interface it belongs to.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4