jQuery UI Checkboxradio enhances checkbox and radio inputs with themeable button-style labels while preserving the underlying native form controls.
$( function () {
$( "input[type=checkbox], input[type=radio]" )
.checkboxradio();
});
Each input should have a unique ID and a matching <label for="...">.
Demo: Checkboxradio with selectable themes →
$( "#my_checkbox" ).checkboxradio({
classes: {
"ui-checkboxradio-label": "ui-state-highlight"
}
});
$( "#my_checkbox" ).checkboxradio({
disabled: true
});
const disabled =
$( "#my_checkbox" ).checkboxradio(
"option",
"disabled"
);
$( "#my_checkbox" ).checkboxradio(
"option",
"disabled",
false
);
Demo: disabled Checkboxradio →
Demo: set disabled true/false from a selection →
For checkboxes, the icon option controls whether the checkbox icon is shown. Radio buttons do not show the checkbox icon.
$( "#my_checkbox" ).checkboxradio({
icon: false
});
$( "#my_checkbox" ).checkboxradio(
"option",
"icon",
true
);
Demo: change the icon option →
Change the text displayed by the associated label.
$( "#my_checkbox" ).checkboxradio(
"option",
"label",
"Updated label"
);
Demo: update Checkboxradio label →
$( "#my_checkbox" ).checkboxradio( "destroy" );
$( "#my_checkbox" ).checkboxradio( "disable" );
Demo: enable/disable with one button →
$( "#my_checkbox" ).checkboxradio( "enable" );
const instance =
$( "#my_checkbox" ).checkboxradio( "instance" );
const options =
$( "#my_checkbox" ).checkboxradio(
"option"
);
Demo: display the Checkboxradio option object →
Checkboxradio reads the underlying input state. If code changes checked directly, update the native property with .prop() and then refresh the widget.
$( "#my_checkbox" )
.prop( "checked", true )
.checkboxradio( "refresh" );
const widget =
$( "#my_checkbox" ).checkboxradio(
"widget"
);
$( "#my_checkbox" ).checkboxradio({
create: function () {
console.log( "Checkboxradio created" );
}
});
The original tutorial includes a grid/matrix example where a Checkboxradio control updates a record.
Demo: update a grid record with Checkboxradio →
Style the generated label class with CSS. Avoid fixing a width unless the design requires it; padding and font size are usually more responsive.
.ui-checkboxradio-label {
font-size: 1rem;
padding: .5rem .8rem;
}
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.