On my page most p-sections under a h3-heading are hidden. If you click on them, the content beneath is shown. Only the first section is shown when the page is opened. I use jQuery to hide these section like:
jQuery("#area h3:first").addClass("active");
jQuery("#area p:not(:first)").hide();
But what, if there is an anchor in one of the other section and the user is linking to it with a # at the end of the url? Right now, it jumps to the hidden section, which is irritating, because the text is not shown. I would not like to hide the section when an anchor in the url is within this section e.g. http://domain.com/page.php#anchor_in_section_3.
How do I prevent the section to hide/collapse?
Detail: After answer 1 I found two problems: If you use .hide and a .show just one line of code later, the sections remains hidden. That seems to fast for jQuery. The other problem is, that with the solution described in answer 1 jQuery only finds the anchor, if it is not in a child tag.
It is more difficult than I thought :)
So the solution described in words is, that all sections except the first and the one containing the anchor tag should be hidden. The anchor can be in any (child)-tag of the section.
Tried 2 hours to transfer this into jQuery but without success with my poor jQuery-knowledge.