Javascript DOM HTML Anchor pathname Property get

Introduction

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

Return the path name of a link:

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

Click the button to display the pathname of the link.

View in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" href="http://www.java2s.com:80/index.html#part1">Example link</a></p>

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*  w  ww.  java 2s  . co m*/
  var x = document.getElementById("myAnchor").pathname;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related