location: pathname property

The pathname property of the Location interface is a string containing the path of the URL for the location. If there is no path, pathname will be empty: otherwise, pathname contains an initial '/' followed by the path of the URL, not including the query string or fragment.


A string.


// Let's say an <a id="myAnchor" href="/en-US/docs/Location.pathname"> element is in the document
const anchor = document.getElementById("myAnchor");
const result = anchor.pathname; // Returns:'/en-US/docs/Location.pathname'


HTML Standard
# dom-location-pathname-dev

Browser compatibility

BCD tables only load in the browser