How to Extract the Current URL and ID in jQuery?

javascript, jquery

Solution

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.

Problem

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

Original source