Thursday, December 22, 2011

Dyanamically add textbox and remove through jquery

$(document).ready(function(){
var counter = 2;
//to add text box
$('#add-textbox').click(function () {
var newTextBoxDiv = $(document.createElement('div'))
.attr('id', 'edit-child-' + counter +'-wrapper');

newTextBoxDiv.after().html('' + '');

newTextBoxDiv.appendTo('#major-id');

counter++;


});

// to remove text box
$('#remove-textbox').click(function () {
counter--;
$('#edit-child-' + counter +'-wrapper').remove();

});

});