Ankit21ks
Ankit21ks

Reputation: 484

how to remove html element dynamically

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 + '');

Upvotes: 0

Views: 102

Answers (1)

Lakshmi Narayana
Lakshmi Narayana

Reputation: 88

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.

Upvotes: 1

Related Questions