This post will discuss how to get hash value from URL using JavaScript and Query.

1. Get hash value for any URL

With pure JavaScript, you can get hash value from a given using the indexOf() and substring(), as demonstrated below:

 
You can also use the split() method with the pop() method, as shown below:

2. Get hash value for the current URL

Alternatively, if you need a hash value for the current window URL, you can just use window.location.hash, which returns a string containing a '#', followed by the fragment identifier of the URL. If the URL does not have a fragment identifier, this returns an empty string, "".

 
With jQuery, you can use the .prop() on the location object to get the hash:

 
To extract only the fragment identifier of the URL without '#', you can use the substr() method like:

 
Here’s another solution using window.location.href.

That’s all about getting hash value from URL using JavaScript and Query.