Reputation: 39
here what I want to do is after selecting input checkbox B when I click on button A (delete) then I want to get all the siblings of selected checkboxes and find the delete button and check if that button is disabled or not. what I tried was
$("body").on('click', '#deleteAll', function (e) {
if ($("input:checkbox").is(':checked').siblings('.delete-website').is(':disabled')){
$("#deleteAll").attr("disabled", true);
}}
Thanks for your time
Upvotes: 1
Views: 204
Reputation: 178350
You mean this?
let dis = $('.someClass:checked')
.map(function() {
return $(this).closest('tr').find('.delete-website:disabled').length > 0
})
.get()
.some(bool => bool)
console.log(dis)
$("#deleteAll").attr("disabled", dis)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label><input type="checkbox" id="deleteAll">Delete all</label>
<table>
<tr>
<td><input type="checkbox" class="someClass" checked></td>
<td><button disabled class="delete-website">Trash</button></td>
</tr>
<tr>
<td><input type="checkbox" class="someClass"></td>
<td><button class="delete-website">Trash</button></td>
</tr>
<tr>
<td><input type="checkbox" class="someClass"></td>
<td><button disabled class="delete-website">Trash</button></td>
</tr>
</table>
Upvotes: 1