Alex Knopp Alex Knopp - 1 month ago 12
jQuery Question

Find an element with unchecked checkbox and remove its ancestor

My HTML

<div class="apartment-entry-container">
<table>
<tr>
<td>
Description
<input type="checkbox">
</td>
</tr>
</table>
</div>
<div class="apartment-entry-container">
<table>
<tr>
<td>
Description
<input type="checkbox">
</td>
</tr>
</table>
</div>

<div><span class="hidenone">Click Here To Hide</div>


MY jQuery

jQuery('.hidenone').click(function(){
jQuery('.apartment-entry-container input:not(:checked)').each(function() {
jQuery(this).parent('.apartment-entry-container').remove();
});
});


Good evening.
I have a list of entities on a page where the user will select the entites they want to include in the coming function. They will include these entites by clicking the checkbox in each .apartment-entry-container.

What I need to do before however is remove all the entites that do not have a checked checkbox.
My code is removing all of the entities checked or not.

Answer

Have you tried this?

https://jsfiddle.net/n28uxcny/

$(".hidenone").click(function() {

    $("input:checkbox:not(:checked)").each(function() {

    $(this).closest('.apartment-entry-container').remove();

});

});