X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook