jQuery remove <form> from a <div>

nic*_*2k3 2 html forms jquery

I've asked about this very example in another question:
Fill in a form with jQuery
but I preferred to create a new one to ask some other details.
I have a div (panel) which currently contains only one form.
This form should represent a list of coordinates. It has some buttons '+' '-' to add or remove a couple of coordinates (and thus the form). Each form is generated automatically by a function and has its own id.

<div id="panel" style="position: absolute; left: 190px; top: 300px; width: 400px; height: 300px; border: medium groove brown; background: none repeat scroll 0% 0% black; z-index: 100; color: white;">  
<form id="form_coord_0">  
X <input type="text" style="height: 25px; font-size: 10px;" size="2" name="X" id="coordX_0"/>  
Y <input type="text" style="height: 25px; font-size: 10px;" size="2" name="Y" id="coordY_0"/>  
<input type="button" id="edit_0" value="M"/>  
<input type="button" id="remove_0" value="-"/>  
<input type="button" id="add_0" value="+"/>  
<input type="button" id="go_0" value="go!"/>  
<br/>  
</div>  
Run Code Online (Sandbox Code Playgroud)

I am looking for a way to:
- remove a line and the associated form
- remove all lines and then all the forms

I have this function:

function add_form(id_coord){  
    var new_form="<form id= '"+ id + "'> </form>";
    $("#panel").append(new_form);
}
Run Code Online (Sandbox Code Playgroud)

这增加了一种形式。
以及添加不同行的 for 循环。
一旦必须删除一行,我更愿意编辑底层数据结构并清空 div。然后它可以由另一个 for 循环重新填充。问题如下:如何删除div的一种形式或每种形式?我想过将 div.innerHTML 设置为 "" 但我真的不喜欢那个解决方案。

jru*_*ell 6

删除一行和相关联的表格

这将删除特定表单。如果这不是您的意思,您可以更改选择器。您可以选择任何元素并使用.remove()删除它们。

$("#specific-form-id").remove();
Run Code Online (Sandbox Code Playgroud)

删除所有行,然后删除所有表格

您可以使用.empty()删除元素的所有子元素。

$("#panel").empty();
Run Code Online (Sandbox Code Playgroud)