Search code examples
twitter-bootstrapanchor

Bootstrap collapse if visiting mydomain.com/#collapseFour


I have a question

I user twitter bootstrap collapse on a page. in the page there are more collapses:

#collapseOne #collapseTwo #collapseThree ...

there are normaly all closed.

but if I visit my link like this: mydomain.com/#collapseFour I want that one collapse automatically be shown.

thank you!


Solution

  • I would do it in PHP just add a class of 'in' to the accordion-body.

    e.g

    <div id="collapseFour" class="accordion-body collapse <?=($_GET['open'] == 4) ? "in" : ""?>">
    

    then your url would be mydomain.com/?open=4

    If you wanted to do it on the hash give this a read Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?

    And check out bootstrap documentation its pretty good!