I have a html table with 10 rows. I want to display first 5 rows of the table for 5 seconds and the next 5 rows for another 5 seconds. When one set of rows are being displayed the other set should be hidden.
Kindly help
Thanks & Regards,
abk
I have a html table with 10 rows. I want to display first 5 rows of the table for 5 seconds and the next 5 rows for another 5 seconds. When one set of rows are being displayed the other set should be hidden.
Kindly help
Thanks & Regards,
abk
Here's a rough and ready way to continuously cycle between the first and last five rows:
$(document).ready(function() {
var $rows = $("table tr"),
i = 0;
function cycle() {
$rows.hide();
$rows.slice(i, i + 5).show();
i = (i + 5) % $rows.length;
setTimeout(cycle, 5000);
}
cycle();
});
You need to break your table into two parts (divs) an then use setTimeout() and JQuery's toggle() to switch the parts. Give it a shot!
Okay, as per my understanding of your requirement, I have coded this. Please check is this what you want.!
<table width="100">
<tr class="first-five-tr">
<td>first</td>
</tr>
<tr class="first-five-tr">
<td>first</td>
</tr>
<tr class="first-five-tr">
<td>first</td>
</tr>
<tr class="first-five-tr">
<td>first</td>
</tr>
<tr class="first-five-tr">
<td>first</td>
</tr>
<tr class="second-five-tr">
<td>second</td>
</tr>
<tr class="second-five-tr">
<td>second</td>
</tr>
<tr class="second-five-tr">
<td>second</td>
</tr>
<tr class="second-five-tr">
<td>second</td>
</tr>
<tr class="second-five-tr">
<td>second</td>
</tr>
</table>
<script>
var hideFirstfive = null;
function hideSecondFive() {
$('.second-five-tr').hide();
$('.first-five-tr').show();
clearInterval(hideSecondfive);
hideFirstfive = setInterval(hideFirstFive, 5000);
}
function hideFirstFive() {
$('.first-five-tr').hide();
$('.second-five-tr').show();
clearInterval(hideFirstfive);
hideSecondfive = setInterval(hideSecondFive, 5000);
}
var hideSecondfive = setInterval(hideSecondFive, 5000);
</script>
here is the working fiddle :) http://jsfiddle.net/Dilip_naga_kumar/HVWDD/