Anchor port Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

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>
<html>
<body>

<p><a id="myAnchor" target="_blank" href="http://www.example.com:443/test.htm#part2">Example link</a></p>

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

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

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

</body>
</html>

Related Tutorials