views:

68

answers:

2

i wanted to know how do you get

http://wesitename.com#overall

How to make a div show when the link is #overall ?

+8  A: 

If the div has an id with the same name, then this should work:

$("#"+location.hash).show();

location.hash will get you the hash-value of a url.

peirix
can i user it like this $("#"+location.hash == "#overview").css({"display":"none"})
Gully
That would beif(location.hash=='#overview') $('#overview').hide();
Josh
A: 

use window.location. On the onLoad event of the page, parse everything after "#" in window.location.toString(), and act accordingly.

Sinan Taifour
Or use location.hash as peirix pointed out. I didn't know about it. It is cross-browser?
Sinan Taifour
Try it yourself in the browsers you are targeting: http://www.w3schools.com/HTMLDOM/prop_loc_hash.asp
Tony Miller
Yeah, it's been in IE since v.4, FF since v.1 and Opera since v.9...should be safe (:
peirix