redconservatory
redconservatory

Reputation: 21924

jQuery: link to an anchor (hidden div) and show?

I have a div, "section" on a page, samplepage.html that I have set the display to "none"

<h3>Title</h3>
<a name="print">
        <div class="section" style="display:none">
            <p>Loreum ipsum text</p>
        </div>

When the user clicks from another page:

<a href="samplepage.html#print">link</a>

I would like to make the "section" div slide open (slideToggle)...is this possible? I don't know how to trigger an event from a click handler on another page...

Upvotes: 0

Views: 1506

Answers (2)

user920041
user920041

Reputation:

There are several libs for handling url routes like this. You may take a look a backbone.js route: http://documentcloud.github.com/backbone/#Router

I would recommend this if you have a lot of routing in your app

Upvotes: 1

Ry-
Ry-

Reputation: 224867

Try this, in a ready handler:

if(document.location.hash) {
    $('.' + document.location.hash.substring(1)).slideDown();
}

Upvotes: 3

Related Questions