Anchor pathname Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor


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>

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

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

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

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;


Related Tutorials