By using jQuery function prop() you can dynamically add this attribute or if present we can change its value i.e. checked=true to make the checkbox checked and checked=false to mark the checkbox unchecked.
$("#chkBox"). attr('checked', true);
Clicking on the master checkbox selects all checkboxes; and unchecking it, deselects all checkboxes.
A jQuery plugin to make your form controls look how you want them to. Now with HTML-5 attributes! Works well with jQuery 1.6+, but we've received patches and heard that this works with jQuery 1.3. Version 4.3.
A simpler solution is to do this rather than using uniform:
$('#check1').prop('checked', true); // will check the checkbox with id check1
$('#check1').prop('checked', false); // will uncheck the checkbox with id check1
This will not trigger any click action defined.
You can also use:
$('#check1').click(); //
This will toggle the check/uncheck for the checkbox but this will also trigger any click action you have defined. So be careful.
EDIT: jQuery 1.6+ uses prop()
not attr()
for checkboxes checked value
Looking at their docs, they have a $.uniform.update
feature to refresh a "uniformed" element.
Example: http://jsfiddle.net/r87NH/4/
$("input:checkbox").uniform();
$("body").on("click", "#check1", function () {
var two = $("#check2").attr("checked", this.checked);
$.uniform.update(two);
});
$("#chkBox").attr('checked', false);
This worked for me, this will uncheck the check box. In the same way we can use
$("#chkBox").attr('checked', true);
to check the checkbox.
If you are using uniform 1.5 then use this simple trick to add or remove attribute of check
Just add value="check" in your checkbox's input field.
Add this code in uniform.js
> function doCheckbox(elem){
> .click(function(){
if ( $(elem+':checked').val() == 'check' ) {
$(elem).attr('checked','checked');
}
else {
$(elem).removeAttr('checked');
}
if you not want to add value="check" in your input box because in some cases you add two checkboxes so use this
if ($(elem).is(':checked')) {
$(elem).attr('checked','checked');
}
else
{
$(elem).removeAttr('checked');
}
If you are using uniform 2.0 then use this simple trick to add or remove attribute of check
in this classUpdateChecked($tag, $el, options) {
function change
if ($el.prop) {
// jQuery 1.6+
$el.prop(c, isChecked);
}
To
if ($el.prop) {
// jQuery 1.6+
$el.prop(c, isChecked);
if (isChecked) {
$el.attr(c, c);
} else {
$el.removeAttr(c);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With