How to get hashtag value on hashchange

You can get the value of #hashtag from the URL if user click on any link in your page. There are two ways to find the id,  First by using Javascript and the second is by jQuery.


By using onhashchange event we can get the hash value, let's see the example:

window.onhashchange = callMyFunction;

function callMyFunction() {
    var hash = window.location.hash;



In the jQuery we can get the hash value by hashchange event, let's see the example:

$(window).on('hashchange', function (e) {

Did you find this page helpful? X