Search code examples
javascriptjqueryanimationjquery-animatejquery-effects

Multiple divs selected with jQuery, select one with #


Here I have some images, when you click one image a div appears. When you click another images the related div appears and the previoulsy loaded one disappears. What I'd like to have is the possibility to load the page with a specific div already loaded. So if I visit http://www.giaule.it/wordpress/?page_id=129#architettonici I'd like the last one appear (#architettonici is the ID that triggers the last one). Or http://www.giaule.it/wordpress/?page_id=129##edifici should "open" the first div.

Ca you help me? Thanks in advance!! :)


Solution

  • I've been waiting over 4 minutes and your page didn't opened yet, but probably I got what you need.

    You might need to use this:

    window.onload = function () {
        if (!!window.location.hash) {
            var hash = window.location.hash;
            /* Your code to open the div */   
        }
    }
    

    Where the var hash is simply the hashlink pulled out from the URL, so you can target a div by ID for instance.

    EDIT

    Here's your revised fiddle: http://jsfiddle.net/9n2tA/1 and here's the working demo: http://fiddle.jshell.net/9n2tA/1/show/light/#edifici