Get and set #hash value in URL using Javascript or jQuery

Get or set #hash value in URL using Javascript or jQuery, we can change URL without refreshing page using Javascript or jQuery by changing #hash value, like below:

  • example.com/page.html#example
  • example.com/page.html#example-page

Javascript or jQuery

// get #hash value
var hashValue = window.location.hash

// set #hash value, it will change URL to example.com/page.html#example-page
window.location.hash = "example-page"

If you have question don't forget to ask.

Thank you for going through

 

1 comment on “Get and set #hash value in URL using Javascript or jQuery”

  1. Gravatar of replica watches uk  replica watches uk
    Posted Sunday, December 9, 2012 at 12:42:36 AM

    Get or set #hash value in URL using Javascript or jQuery

Post a comment