0

I have the following code which works well to open / close / toggle a series of divs.

$("a").click(function(){
 var myelement = $(this).attr("href")
 $(myelement).slideToggle("slow");
 $(".toggle:visible").not(myelement).hide();

});  

What I would like is for the div to remain open if the page is refreshed, or saved with the anchor link. ie. the finance div should stay open if the url is:

http://mywebsite/page#finance

Thanks

TJ-
  • 14,085
  • 12
  • 59
  • 90
user579984
  • 160
  • 6
  • 1
    Follow these leads to detect an anchor in your link : http://stackoverflow.com/questions/298503/how-can-you-check-for-a-hash-in-a-url-using-javascript and http://stackoverflow.com/questions/3552944/how-to-get-the-anchor-from-the-url-using-jquery You may hide the divs initially (by css) and show them only when an anchor tag is present or vice versa. – TJ- Dec 03 '12 at 20:40

1 Answers1

0
var h = window.location.hash;
$("#" + h).show();

This assumes your div's id is that of the value in the URL hash.

Tim Hobbs
  • 2,017
  • 17
  • 24