0

Is there a 'best practice' how to hide all except one content-DIV of an HTML5 website? Is there also a 'most used' library/libraries? Or is it often written in own JS code?

My goal is to have 9 DIVs loaded. The one in the center is the navigation, the others are content. When a nav-point is selected the specific div 'slides' to the middle and all the other DIVs are hidden.

Thank you

2
  • "Is there also a 'most used' library/libraries?" - Well jQuery is used a lot precisely because it makes this sort of thing trivial, but there are other options. Writing it from scratch in "plain" JS wouldn't be particularly difficult either. Given you tagged your question with "jquery" are you asking whether there is a better library for this purpose? Commented Jun 26, 2012 at 5:21
  • Hi! thanks a lot for the help!! It works :-) About my 'jquery' question, I was just wondering if there is a dedicated library for this kind of implementation. Commented Jun 26, 2012 at 17:18

3 Answers 3

1

I usually do this:

$('.your_div').show().siblings().hide();

Replace .show() and .hide() with your desired effects.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 siblings() is great but it might be too broad a selector in his use case.
Maybe .siblings('.your_div') would be better?
I like that. Add it. I can't think of a reason the sections would have different parentage. :)
0

I would add a class to all the hide and show able divs probably a class name like section.

<div class="section" id="home"> home content here... </div>
<div class="section" id="page-slug"> another page here... </div>
<div class="section" id="contact"> contact information here... </div>

Then give each div an id. FInally, in order to show the contact section you would:

$('#contact').show().siblings('.section').hide();

This method of giving like elements the same classand giving container elements an id is really just good practice regardless of the ease of use when selecting jQuery elements.

Comments

0

Jquery's hide, .show or .toggle are good enough.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.