Anchor port Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor


The port property sets or gets the port part of the href attribute value.

Property Values

Value Description
number Sets the port number of a URL

Return Value

A String, representing the port number of the URL

The following code shows how to Return the port number of a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<p><a id="myAnchor" target="_blank" href="">Example link</a></p>

<button onclick="myFunction()">Get the port number of the link above</button>

<p id="demo"></p>

function myFunction() {//from  w  w  w. j av  a2s.c o  m
    var v = document.getElementById("myAnchor").port;
    document.getElementById("demo").innerHTML = v;


Related Tutorials