THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Anchor pathname Property

Anchor Object Reference Anchor Object

Example

Return the path name of a link:

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

The result of x will be:

/test.htm
Try it yourself »

Definition and Usage

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

Internet Explorer Firefox Opera Google Chrome Safari

The pathname property is supported in all major browsers.


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 Reference Anchor Object