Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"checkboxes",
"jquery",
"plugin",
"randomcheck",
"check",
"uncheck",
"range",
Expand Down
11 changes: 11 additions & 0 deletions src/jquery.checkboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
var Checkboxes = function (context) {
this.$context = context;
};

/**
* Random check all checkboxes in context. New!!! By cottayson
*/
Checkboxes.prototype.randomcheck = function () {
this.$context.find(':checkbox')
.filter(':not(:disabled)')
.each(function () {
$(this).prop( 'checked', parseInt(2*Math.random()) );
});
};

/**
* Check all checkboxes in context.
Expand Down
7 changes: 5 additions & 2 deletions tests/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@
<a href="#checkboxes"
data-toggle="checkboxes"
data-action="check">Check all</a>
<a href="#checkboxes"
<a href="#checkboxes"
data-toggle="checkboxes"
data-action="uncheck">Uncheck all</a>
<a href="#checkboxes"
data-toggle="checkboxes"
data-action="randomcheck">Check random</a>
<label>
<input type="checkbox"
data-context="#checkboxes"
Expand All @@ -55,4 +58,4 @@
Check all
</label>
</body>
</html>
</html>