Anchor pathname Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

The pathname property sets or gets the path name part of the href attribute value.

Property Values

Value Description
path Sets the path name of a URL

Return Value

A String, representing the path name of the URL

The following code shows how to Return the path name 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:80/test.htm#part2">Example link</a></p>

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

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

<script>
function myFunction() {/*from   w w  w .  j a v  a2 s.c  o m*/
    var v = document.getElementById("myAnchor").pathname;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials