views:

48

answers:

4

Basically I hide all of the answer divs on the page, but I want to show a div if the a user has clicked a bookmarked link to it.

Here's the javascript code

<script type="text/javascript">
    $(document).ready(function(){
        //hide the all of the element with class msg_body
        $(".faq_answer").hide();
        //toggle the componenet with class msg_body
        $(".faq_question").click(function(){
            $(this).next(".faq_answer").slideToggle("normal");
        });
    });
</script>

The resulting HTML for the section is

<li>
  <div class="faq_question">
     <a href="#url-blah" name="url-blah">Question</a>
  </div>
  <div class="faq_answer">
    <p>Text to show</p>
    </div>
</li>

EDIT

The question was how do I do it...Figured it out though after the answers here.

+3  A: 

window.location.hash will give you the value "#" in your URL. You can use that to build a selector.

// if visiting /index.php#item1
$(window.location.hash).show(); // $('#item1').show();
Jonathan Sampson
Did this and then added the window.location.hash value to the id of the answer link.
silent1mezzo
A: 

I would assume you would need to add a class to the div that hides it and shows it based on the click function

I dont really see a question here though

codemypantsoff
+1  A: 

You can look for the #url-blah in the URL in javascript and display the corresponding section?

Chetan Sastry
A: 

To accomplish this you are going to most likely need to change your document structure a bit, as you cannot reference any of the specific "faq_answer" items individually.

Typically what I would do here is use a specific ID for each of the answers, then you can use javascript with a show action to be able to toggle visibility.

For an example of my HTML and jQuery code, you can view this page, look at the version history section.

Mitchel Sellers