简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM