Here is the code and the jsFiddle http://jsfiddle.net/yh3rynab/1/
var i = 1;
$('body').on('click', '#add_row', function () {
if (i >4) {
alert("No more");
return;
}
$('#fg01_container').append('<div class="form-group" id="fg01_0' + i + '"></div>');
$('#fg01_0' + i).html('<div class="col-md-2 col-md-offset-4">CONTENT</div>');
i++;
});
$('body').on('click', '#delete_row', function() {
if (i > 1) {
$("#fg01_0" + (i - 1)).remove;
i--;
}
});
The code adds fine but it doesn't remove the element that was just created. Please advise!