Example 1 — Official Demo: check() and uncheck()
The jQuery API sample adds two methods that tick or clear every matched checkbox.
jQuery.fn.extend({
check: function () {
return this.each(function () { this.checked = true; });
},
uncheck: function () {
return this.each(function () { this.checked = false; });
}
});
// Use the newly created methods
$("input[type='checkbox']").check();
console.log($("#a").prop("checked")); // true
$("input[type='checkbox']").uncheck();
console.log($("#a").prop("checked")); // false How It Works
- Extend. One object with two functions is merged onto
jQuery.fn. - Loop.
this.each()visits every checkbox in the collection. - Chain.
return this.each(...)hands the collection back to the caller.

