jquery marque desmarque todas las casillas de verificación con un botón
Estoy tratando de marcar / desmarcar todas las casillas de verificación usando jquery. Ahora, al marcar / desmarcar la casilla de verificación principal, todas las casillas de verificación secundarias se seleccionan / deseleccionan también con el texto de la casilla de verificación principal que se cambia a checkall / uncheckall.
Ahora quiero reemplazar la casilla de verificación principal con un botón de entrada y cambiar el texto también en el botón para marcar / desmarcar. Este es el código, ¿alguien puede modificar el código ...
$( function() {
$( '.checkAll' ).live( 'change', function() {
$( '.cb-element' ).attr( 'checked', $( this ).is( ':checked' ) ? 'checked' : '' );
$( this ).next().text( $( this ).is( ':checked' ) ? 'Uncheck All' : 'Check All' );
});
$( '.cb-element' ).live( 'change', function() {
$( '.cb-element' ).length == $( '.cb-element:checked' ).length ? $( '.checkAll' ).attr( 'checked', 'checked' ).next().text( 'Uncheck All' ) : $( '.checkAll' ).attr( 'checked', '' ).next().text( 'Check All' );
});
});
<input type="checkbox" class="checkAll" /> <b>Check All</b>
<input type="checkbox" class="cb-element" /> Checkbox 1
<input type="checkbox" class="cb-element" /> Checkbox 2
<input type="checkbox" class="cb-element" /> Checkbox 3