Selecting within a selection
Posted: Wed Jul 25, 2012 11:27 am
I have the following javascript:
This loops through every row in a table, and displays them one after the other.
However, within that table each row has a class of either 'group1', 'group2', 'group3'.
I need to modify the above javascript so that:
[text]If there are rows with 'Group 1' it loops through only those, and all others remain hidden,
else
If there are rows with 'Group 2' it loops through only those, and all others remain hidden,
else
it loops through all those rows with 'group 3' (which would be all of them as that is the default).[/text]
But I can't figure how to do it. in my head it sounds like it should be really easy, but I just can't figure out how to do it in my script. Can any one advise?
Code: Select all
var b = 1;
function showRows2()
{
var $rows2 = $('#dbTable2 tr');
$rows2.css('display','none');
$rows2.eq(0).css('display','table-row'); //Display Header
$rows2.eq(b).css('display','table-row'); //Show Row
b = (b == $rows2.length-1) ? 1 : b + 1; //increment by one
};
function hideShow2(time)
{
timer2 = setInterval('showRows2()',time);
};
However, within that table each row has a class of either 'group1', 'group2', 'group3'.
I need to modify the above javascript so that:
[text]If there are rows with 'Group 1' it loops through only those, and all others remain hidden,
else
If there are rows with 'Group 2' it loops through only those, and all others remain hidden,
else
it loops through all those rows with 'group 3' (which would be all of them as that is the default).[/text]
But I can't figure how to do it. in my head it sounds like it should be really easy, but I just can't figure out how to do it in my script. Can any one advise?