Find last names in url after # - jquery / javascript

Is there a way to get the last names after the # in the url in jquery / javascript

I want to find the names #prices and do an if if

if( the_last_name == 'prices' ) 
// do something

      

I need js / jquery to find a way to get the name of the last url (and check it against if stat / the_last_name)

+2


source to share


2 answers


Use this:

document.location.hash

      



eg:

if (document.location.hash == "#prices") {

      

+8


source


Better, use this:

if (document.location.hash.substr(1) == "prices") {

      



so that you don't have "#" in your line.

+3


source







All Articles