Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to delete dynamically added html code block

I have a button which dynamically creates html content enclosed in <fieldset> like this.:

<div id="box_parent"></div>

Javascript

var content = '<fieldset>Some Content <input id="delete_row_box" type="button" value="Delete"></fieldset>';
$("#box_parent").append(content);

How can I make the dynamically created delete button only deletes the html block that it only belongs to?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’m stuck on this function:

$(document).on("click", '#delete_row_box', function() {
    console.log(this);
});

I think .remove() should do it but I don’t know how to throw the correct reference

>Solution :

Select its parent then delete the fieldset you add

$(this).parent().remove()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading