0
First, there’s this question about Check/Uncheck all checkboxes except disabled checkboxes, however I do not want you to uncheck what is already marked when you click again. I want you to uncheck all the checkboxes, but if you have an appointment, it must remain marked.
The idea is to check whether most checkboxes are marked, then uncheck them. Otherwise, mark them.
I have the following code below, see:
$(document).on("click", "#checkAll", function(){
$('input[type="checkbox"]').prop("checked", true);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td><input type="checkbox"/>Jon Snow</td>
</tr>
<tr>
<td><input type="checkbox"/>Tony Stark</td>
</tr>
<tr>
<td><input type="checkbox"/>Paul McCartney</td>
</tr>
<tr>
<td><input type="checkbox"/>Luke Skywalker</td>
</tr>
<tr>
<td><input type="checkbox"/>Pablo Escobar</td>
</tr>
</table>
<button style="float: left;" type="button" class="btn btn-default btn-xs" id="checkAll">Botão</button>
I would like you to click again, uncheck the checkboxs. What better way to do it?
Your question was confused. If you have 2 checked and click the button, what should happen?
– Sam
@Davidsamm if you have two 2 marked and you have not once clicked on everything, he must mark the rest that are unchecked.
– viana
You want to check if the "mark all" button has been clicked before?
– Sam
If I understand, you just want to know if at least half of the boxes are marked. If so, clear everything, otherwise check those that are empty.
– Sam
@Davidsamm if this is a way out, it could be. What I don’t want is for it to be the same as the answer to the question I mentioned https://jsfiddle.net/wzeobpf2/. Because the moment I click on mark everything [example], it unchecks those that are already marked. [How difficult to explain =/]
– viana