0

I have two functions in mycode.first is addElement() and second is removeElement() When I click on add it is adding elements dynamically, Now what I want to remove those elements dynamically when I click on remove. I tried .remove() and .empty() but its not working. Please help. add code:

$('#original').append('<br/><br/><strong>And &nbsp; </strong>');
                        var content = '<select name=selParameter' + count + ' id=selParameter' + count + ' class=chosen-select><option value=0>Select Parameter</option>';

remove code: $('#original').remove('#selParameter' + count + '');

sahil gupta
  • 2,339
  • 12
  • 14
Ankit21ks
  • 468
  • 1
  • 7
  • 22

1 Answers1

1

The problem here is you are adding the content to the HTML page after page is loaded, the same will work if you have done before the page load.

There is on function in jQuery to record changes and remove the elements dynamically when they are added. Please have a look at the following documentation http://api.jquery.com/on/

Let me know, if you still face issues.

Lakshmi Narayana
  • 88
  • 1
  • 1
  • 9
  • which event am I suppose to use like load or else – Ankit21ks Aug 27 '15 at 11:51
  • $(document).ready(function(){ $("#add").on('click', function(){ alert('add'); $('body').append("

    this is added

    ") }) $('#remove').on('click', function(){ alert('remove'); $('#added').remove() }) });
    – Lakshmi Narayana Aug 27 '15 at 11:57