0

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

1
  • I made you a quick demo here. You didn't say you wanted to keep the old ones as they do on the BBC site so I kept that feature out JSFiddle Commented Oct 18, 2010 at 7:27

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.