Easy, the solution is to use $('xxxxxx').prop('checked', true) or false Test OK in Jquery 1.11.x.
Cheers
FULL DEMO CODE EXAMPLE
Examples: (Code JavaScript checkbox for a table)
function checkswich() { if ($('#checkbox-select').is(':checked') == true) { selectTodo(); } else { deSelectTodo(); } } function selectTodo() { //$('#tabla-data input.ids:checkbox').attr('checked', 'checked'); $('#tabla-data input.ids:checkbox').prop('checked', true); } function deSelectTodo() { //$('#tabla-data input.ids:checkbox').removeAttr('checked', 'checked'); $('#tabla-data input.ids:checkbox').prop('checked', false); } function invetirSelectTodo() { $("#tabla-data input.ids:checkbox").each(function (index) { //$(this).attr('checked', !$(this).attr('checked')); $(this).prop('checked', !$(this).is(':checked')); }); }
Examples: (Code HTML checkbox for a table)
<table id="tabla-data" class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr> <th class="text-center" style="width: 5px"><span class="glyphicon glyphicon-check"></span></th> <th>Engine</th> <th><a href="#" class="">Browser</a></th> <th class="td-actions text-center" style="width: 8%;">Acciones</th> </tr> </thead> <tbody id="tabla-data" class="checkbox-data"> <tr> <td class="text-center"><input type="checkbox" class="ids" name="[]id" value=""></td> <td>#########</td> <td>#######</td> <td class="td-actions text-center"> <?= $this->element('table-data-bts',['id'=>1234,'action'=>['view'=>'view', 'edit'=>'edit', 'delete'=>'delete']]) ?> </td> </tr> <tr> <td class="text-center"><input type="checkbox" class="ids" name="[]id" value=""></td> <td>#########</td> <td>#######</td> <td class="td-actions text-center"> <?= $this->element('table-data-bts',['id'=>1234,'action'=>['view'=>'view', 'edit'=>'edit', 'delete'=>'delete']]) ?> </td> </tr> <tr> <td class="text-center"><input type="checkbox" class="ids" name="[]id" value=""></td> <td>#########</td> <td>#######</td> <td class="td-actions text-center"> <?= $this->element('table-data-bts',['id'=>1234,'action'=>['view'=>'view', 'edit'=>'edit', 'delete'=>'delete']]) ?> </td> </tr> </tbody> </table>
Example: (Code ComponentHTML use JavaScript)
<form id="form-datos" action="/url/demo/blablaaa" method="post" enctype="multipart/form-data" style="visibility: hidden;" > <input type="hidden" name="accion" id="accion">
<div class="btn-group"> <span class="btn btn-default btn-xs"><input type="checkbox" id="checkbox-select" onclick="checkswich()"></span> <button type="button" class="btn btn-default btn-xs dropdown-toggle dropdown-toggle-check" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <span class="caret"></span> <span class="sr-only">Options</span> </button> <ul class="dropdown-menu"> <li><a href="#" onclick="accion()">Action Demo</a></li> <li role="separator" class="divider"></li> <li><a href="#" onclick="selectTodo()">Select All</a></li> <li><a href="#" onclick="deSelectTodo()">UnSelet All</a></li> <li><a href="#" onclick="invetirSelectTodo()">Inverse Select</a></li> </ul>
propinstead ofattrif usingjQuery 1.6+and also can you provide code onjsfiddle