views:

238

answers:

2

Hey

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

I want to find the names #prices and make an if statment

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

I need js/jquery to find a way to get urls last name ( and check it on the if statment /the_last_name)

+4  A: 

Use this:

document.location.hash

eg:

if (document.location.hash == "#prices") {
nickf
omg thank you!
william
+1  A: 

Better, use this:

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

so you don't have the '#' in your string.

Time Machine
why not use the *other* way so don't have `.substr(1)` in your code? 1 extra char vs 10.
nickf