Reputation: 3
I would like to have a table with 10 rows 5 of which are visible. Also 2 buttons - and + and if clicked a row is added or removed, same as the + image in the bbc.co.uk site. How would i accomplish this
Upvotes: 0
Views: 1364
Reputation: 8237
Just add Listeners and use remove & append:
<table id="table">
<tr>
<td>foo</td>
</tr>
<tr>
<td>bar</td>
</tr>
</table>
<span id="plus">+</span>
<span id="minus">-</span>
<script type='text/javascript' src='http://code.jquery.com/jquery-latest.min.js'></script>
<script>
$(document).ready(function () {
$('#minus').click(function(){
$('#table tr:last-child').remove();
});
$('#plus').click(function(){
$('#table').append('<tr><td>new</td></tr>');
});
});
</script>
Upvotes: 2