views:

89

answers:

3

How would I go about getting the current URL using jquery, or more specifically, getting an ID on the end of it?

For example, I have product.php#tab-2. What I want to get from it is just the '#tab-2' part.

I have tried 'window.location.pathname' but that will only return '/product.php'

Thanks

A: 

Use jqUrl plugin (http://www.oakcitygraphics.com/jquery/jqURL/jqURLdemo.html) to retrieve the full current url, then strip the window.location.pathname part.

Thomas

Thomas
+2  A: 

You don't need jQuery for this:

alert(window.location.href); // will give you the full url
alert(window.location.hash); // will give you the hash (#) value

See the Mozilla docs at window.location - MDC.

Andy E
+1  A: 

You want window.location.hash

andynormancx