Javascript examples for DOM HTML Element:Anchor
The pathname property sets or gets the path name part of the href attribute value.
Value | Description |
---|---|
path | Sets the path name of a URL |
A String, representing the path name of the URL
The following code shows how to Return the path name of a link:
<!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>