[英]JQuery remove label checkbox
I have the following code to create checkboxes (puntosD is a div I created where I append the checkbox): 我有以下代码来创建复选框(puntosD是我在添加复选框的位置创建的div):
$("div.puntosD").append('<input type=\"checkbox\" id="checkpuntos" name="'+data[index].id+'" value="'+data[index].nombre+'"> '+data[index].nombre);
I have the following code to remove the checkboxes: 我有以下代码来删除复选框:
$("input[type='checkbox']").next('label').remove();
$("input[type='checkbox']").remove();
This however only removes the actual boxes to tick but not the labels, how can I do this? 但是,这只会删除要打勾的实际框,而不会删除标签,我该怎么做?
Thank you! 谢谢!
How about this, wrap the checkbox and label in span: 怎么样,将复选框和标签包裹在span中:
$("div.puntosD").append('<span><input type=\"checkbox\" id="checkpuntos" name="'
+ data[index].id+'" value="'+data[index].nombre+'">'
+ data[index].nombre+'</span>');
remove the span: 删除跨度:
$("input[type='checkbox']").parent('span').remove();
I am not sure if you are trying to remove all the checkbox & label inside the div or remove specific checkbox & label inside the div. 我不确定您是要删除div中的所有复选框和标签,还是要删除div中的特定复选框和标签。
You can use .empty
on that div in case if you only had checkbox & label inside the div and you want to remove them all. 如果只有div内的复选框和标签并且您想要将其全部删除,则可以在该div上使用
.empty
。
$('div.puntosD').empty();
If you want to remove specific, then wrap it with a span and remove the span using below code, 如果您要删除特定内容,请用一个跨度将其包裹起来,并使用以下代码删除该跨度,
$(':checkbox[name="1"]').parent('span').remove();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.