Anchor pathname Property
Example
Return the path name of a link:
var x = document.getElementById("myAnchor").pathname;
Try it Yourself »
Description
The pathname property sets or returns the path name part of the href attribute value.
Note: In the example above, IE 9 and earlier versions returns "test.htm", while IE 10 and higher, Firefox, Opera, Chrome, and Safari returns "/test.htm".
Browser Support
Property | |||||
---|---|---|---|---|---|
pathname | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the pathname property:
anchorObject.pathname
Set the pathname property:
anchorObject.pathname = path
Property Values
Value | Description |
---|---|
path | Specifies the path name of a URL |
Technical Details
Return Value: | A String, representing the path name of the URL |
---|
More Examples
Example
Change the path name of a link:
document.getElementById("myAnchor").pathname = "newpathname";
Try it Yourself »
Related Pages
JavaScript reference: location.pathname Property
❮ Anchor Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.