Anchor port attribute

Definition and usage

port Property setting or return href attribute value The port part.

Note:If the port number is not specified in the URL (or if it is the default port of the protocol - for example, 80 or 443), some browsers will display 0 or not display it.

See also:

JavaScript Reference Manual:location.port attribute

Example

Example 1

Return the port number of the link:

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

Try it yourself

Example 2

Change the port number of the link:

document.getElementById("myAnchor").port = "80";

Try it yourself

Syntax

Return the port attribute:

anchorObject.port

Set port attribute:

anchorObject.port = number

Attribute Value

Value Description
number Specifies the port number of the URL.

Technical Details

Return Value: A string value representing the port number of the URL.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support