views:

12

answers:

1

Can anyone guide me to delete the first div, when there are 5 div's

I'm cloning a text box, users can add multiple textbox's but when it reaches to 5, i should automatically delete the first textbox and add another at the end of the node

Thanks

+1  A: 

With jQuery:

You need to count all of these divs and remove first one:

count = $('#container div').length;
if (count > 5) {
    $('#container div:first').remove();
}

To add new div:

$('#container').append('<div ...><textbox...></textbox></div>');
Māris Kiseļovs