2012-10-22 42 views
0

我有一個有一些div的頁面。我在這些div上顯示圖像。有時候,一些div可能是空的,有些可能有價值。加載只有在jquery中有數據的div

點擊一個div,我顯示另一個div與圖像。並且,點擊帶有圖像的div應該會讓我回到原來的位置。我知道這很複雜。 .group css類包含一堆divs。我只想展示那些有價值的div。下面的代碼有點作品,但因爲我這樣做($('。group')。show();),它顯示了所有的div和全部圖像的顯示。有沒有辦法清除這些emtpy div,以便只顯示帶有圖片的div並清除其他圖片。謝謝。

$(function() { 
      $('#individual').click(function() { 
      $('.aggregate').hide(); 
      $('#aggregate').show(); 
      }); 

       $('#aggregate').click(function() { 
        $('#aggregate').hide(); 
        $('.group').show(); 
       }); 
    }); 
+0

HTML請??? –

回答

1

這項工作?

$(function() { 
      $('#individual').click(function() { 
      $('.aggregate').hide(); 
      $('#aggregate').show(); 
      }); 

       $('#aggregate').click(function() { 
        $('#aggregate').hide(); 
        $('.group').each(function(){ 
         if($(this).html()!='') 
          $(this).show(); 
        }); 
       }); 
    }); 
+0

http://api.jquery.com/parent-selector/ – mplungjan

+0

@ user1026361,謝謝。 – user1471980

相關問題