tags:

views:

58

answers:

2

I have 3 html box as follow:

<div class="tabs">
  <ul class="tabNav">
    <li><a href="#video">Video Gallery</a></li>
    <li><a href="#photo">Photo Gallery</a></li>
  </ul>
  <div  id="video"> video div </div>
  <div  id="photo"> photo div </div>
</div>
 <div class="tabs">
  <ul class="tabNav">
    <li><a href="#comment">comment</a></li>
    <li><a href="#links">links</a></li>
  </ul>
  <div  id="comment"> comment div </div>
  <div  id="links"> links div </div>
</div>

for show and hide tabs i used this jquery code:

$(function () {
     var container = $('div.tabs > div');
     container.hide().filter(':first').show();

     $('div.tabs ul.tabNav a').click(function () {
     container.hide();
     container.filter(this.hash).show();
     $('div.tabs ul.tabNav a').removeClass('selected');
     $(this).addClass('selected');
     return false;
     }).filter(':first').click();
  });

This code only works with firts box (gallery) and with page load, the comment and links are also hidden. How can I solve this? Thanks in advance

+2  A: 

What exactly are you trying to do here?

tarnfeld
I was thinking the same. What do you want to achieve?
asrijaal
with only one html box and jquery code, all things work well.<div id="photo"> photo div </div> is hidden and I have a perfect tabbed jquery navigation.But when i have more boxes in my page, I want that <div id="photo"> photo div </div> and <div id="links"> links </div> (second div in every box) be hidden. But in my code, only <div id="video"> video div </div>is shown and others are hidden.
Copy my javascript, tarnfeldweb.com
tarnfeld
A: 

If I understand you correctly, you want those tabs to work separately of each other, i.e select photo and links at the same time so photo div and links div will be shown. In your code you operate in joined environment, you can select any of those four divs but only one of them will be shown. In order to operate div.tabs separately, following code will work:

$(function () {
   $('div.tabs').each(function(i, tabs) {
      var container = $('div', tabs);
      container.hide().filter(':first').show();

      $('ul.tabNav a', tabs).click(function () {
          container.hide();
          container.filter(this.hash).show();
          $('ul.tabNav a', tabs).removeClass('selected');
          $(this).addClass('selected');
          return false;
      }).filter(':first').click();
   });
});

Note that at first it selects div.tabs and then do it's magic inside that div for each of them.

vava
thank you vava;but with above code, the forth div also shown :(
@jasmine, so, you want to show either video and comments divs or photo and links divs together but not video and links divs nor photo and comments? Is that what you want?
vava
yes vava, that is I want.
@vava;With playing around css your code working perfect for all boxes.