Question in the dom about deleting a specific element [closed]

im making a small comment section and want to add a delete comment feature which pops up a modal to confirm delete or cancel and when i click cancel it just saves the previous parent element like in this picture [1]: https://i.stack.imgur.com/DA4d3.jpg. whenever i click cancel it just keeps adding so i really have hard times figuring this out and i need a bit of direction here. here’s my code [2]: https://i.stack.imgur.com/F7432.jpg