I have a table with some rows having a style display tag style="display: none;"
and a toggle-all checkbox. I'm trying to make my "select all" script only check the checkboxes that are visible in rows with tag style="display: none;"
.
This is the script i have so far, but it checks everything, regardless of visibility. How can i check/uncheck only those that are visible?
Script
$('#select-all').click(function (event) {
if (this.checked) {
$(':checkbox').each(function () {
this.checked = true;
});
}
if (!this.checked) {
$(':checkbox').each(function () {
this.checked = false;
});
}
});
Toggle all checkbox
<input name="select-all" id="select-all" type="checkbox" value="checked" aria-label="..." style="cursor:pointer">
Table
<table>
<tbody>
<tr>
<td>Checkbox</td>
<td>#</td>
<td>Number</td>
<td>Title</td>
</tr>
<tr style="display: table-row;">
<td><input type="checkbox" name="f1" value="1"></td>
<td>1</td>
<td>Number1</td>
<td>Title1</td>
</tr>
<tr style="display: none;">
<td><input type="checkbox" name="f2" value="1"></td>
<td>2</td>
<td>Number2</td>
<td>Title2</td>
</tr>
...
<tr style="display: table-row;">
<td><input type="checkbox" name="f3" value="1"></td>
<td>3</td>
<td>Number3</td>
<td>Title3</td>
</tr>
</tbody>
</table>
Aucun commentaire:
Enregistrer un commentaire