2010-03-26 4 views
-2
$(".sectionHeader").click(function() { 
    var row = $(this).parent(); 
    while (row.next().length != 0) { 
     row = row.next(); 
     if (row.children().first().is('th')) return; 
     row.toggle(); 
    } 
}); 

답변

2

당신이 경우에,이 같은 다음 sectionHeader까지 축소 할 수 있습니다, 섹션 헤더있는 테이블의 행을 것 같습니다 :

$(".sectionHeader").click(function() { 
    $(this).closest("tr").nextUntil(".sectionHeader").toggle(); 
}); 

는 당신이 좀 더 효율적으로 만들 수있다 이 같은 delegate() :

$("#sectionTable").delegate(".sectionHeader", "click", function() { 
    $(this).closest("tr").nextUntil(".sectionHeader").toggle(); 
}); 

.sectionHeader 행 당 하나의 이벤트 전체 테이블에 대한 핸들러 대신 1을 연결합니다.

0
$(".sectionHeader").click(function() { 
    $(this).parent().each(function(index, element){ 
     if($(element).children().first().is('th')) return; 
     $(element).toogle(); 
    }); 
}); 
관련 문제