How to Check for a Hash Value in a URL Using JavaScript
Read this tutorial and learn the fastest and simplest way of checking for a hash value in the URL using the window.location.hash method in JavaScript.
The web page elements are modified depending on the hash (#) value of the current URL. You can get the hash value from the URL quickly by just running JavaScript code.
You can use the <kbd class="highlighted">window.location.hash</kbd> property to get the hash:
JavaScript: Get hash using window.location.hash
The window.location.hash property contains the fragment identifier, including the hash ‘#’ sign for the current page. For example:
http://w3docs.com/#foo
Here, the property would return the fragment identifier of \#foo .
The window.location Property
The <kbd class="highlighted">location</kbd> interface represents the URL of the object to which it belongs. The changes that are done on it are reflected in the object to which it relates. The <kbd class="highlighted">window.location</kbd> is a reference to a <kbd class="highlighted">location</kbd> object representing the current URL of the document being displayed in that window.