-1

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!

pee2pee
  • 3,619
  • 7
  • 52
  • 133

2 Answers2

2

Remove is a function. call it like remove()

 $("#fg01_0" + (i - 1)).remove();
SSA
  • 5,433
  • 4
  • 36
  • 50
1

remove is method and not property in jquery. You should use .remove() instead of .remove

 $("#fg01_0" + (i - 1)).remove();

Working Demo

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125