Anchor pathname attribute

Definition and usage

pathname Property setting or return href attribute value the pathname part.

Note:In the above example:

  • IE 9 and earlier versions return "test.html"
  • IE 10 and later versions, Firefox, Opera, Chrome, and Safari return "/test.html"

See also:

JavaScript Reference Manual:location.pathname attribute

Example

Example 1

Return the pathname of the link:

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

Try it yourself

Example 2

Change the pathname of the link:

document.getElementById("myAnchor").pathname = "newpathname";

Try it yourself

Syntax

Return the pathname attribute:

anchorObject.pathname

Set pathname attribute:

anchorObject.pathname = path

Attribute Value

Value Description
path Specifies the path name of the URL.

Technical Details

Return Value: A string value representing the path name of the URL.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support