I have a URL like this http://localhost/sites/fh/index.php#second
. I want to fetch the id from the URL end and store it in a variable container to check in if else statement in jquery. How can I do so?
Asked
Active
Viewed 97 times
0
-
1Possible duplicate of [On - window.location.hash - Change?](http://stackoverflow.com/questions/680785/on-window-location-hash-change) – José Luis Feb 07 '17 at 15:02
1 Answers
4
Window is a global javascript object,
You use window.location.hash to get the hash value, it will return null if there is no hash present.
var hashValue=window.location.hash;
console.log(hashValue);

Parth Ghiya
- 6,929
- 2
- 30
- 37
-
-
-
Thanks... and how can I change the URL #id when I scroll down or up to load a particular ID section? Example: when I scroll down to `` then the URL should change to #second automatically and the same when I scroll up.. can u give a different answer for that? – Feb 07 '17 at 13:36