Sunday, April 3, 2011

how to use url and jquery

i wanted to know how do you get

http://wesitename.com#overall

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

From stackoverflow
  • 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.

    Gully : can i user it like this $("#"+location.hash == "#overview").css({"display":"none"})
    Josh : That would be if(location.hash=='#overview') $('#overview').hide();
  • 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?
    Tony Miller : Try it yourself in the browsers you are targeting: http://www.w3schools.com/HTMLDOM/prop_loc_hash.asp
    peirix : Yeah, it's been in IE since v.4, FF since v.1 and Opera since v.9...should be safe (:

0 comments:

Post a Comment