$(".sectionHeader").click(function() {
var row = $(this).parent();
while (row.next().length != 0) {
row = row.next();
if (row.children().first().is('th')) return;
row.toggle();
}
});
views:
66answers:
2
A:
$(".sectionHeader").click(function() {
$(this).parent().each(function(index, element){
if($(element).children().first().is('th')) return;
$(element).toogle();
});
});
VinTem
2010-03-26 20:23:55
+1
A:
It looks like you have rows in the table that are section headers, in that case, you can collapse until the next sectionHeader like this:
$(".sectionHeader").click(function() {
$(this).closest("tr").nextUntil(".sectionHeader").toggle();
});
You could make it more efficient with delegate()
like this:
$("#sectionTable").delegate(".sectionHeader", "click", function() {
$(this).closest("tr").nextUntil(".sectionHeader").toggle();
});
This attaches one event handler for the entire table instead of 1 per .sectionHeader
row.
Nick Craver
2010-03-26 21:06:29