Last active
August 29, 2015 13:56
-
-
Save bensochar/9215365 to your computer and use it in GitHub Desktop.
jQuery snippet to Detect Checkbox Changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) { | |
$(':checkbox').checkedChange(); | |
}); | |
(function($) { | |
/* | |
* Detect Checkbox Changes | |
*/ | |
$.fn.checkedChange = function (_class) { | |
_class = _class || "checked"; | |
return this.each(function () { | |
var _label = $(this).closest("label.checkbox"); | |
var _nme = this.name; | |
if(!navigator.userAgent.match(/MSIE/) ) { | |
$(this).change(function() { | |
$(this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class); | |
}); | |
} else { | |
$(_label).click(function() { | |
$(':checkbox', this).is(":checked") ? _label.addClass(_class) : _label.removeClass(_class); | |
}); | |
} | |
$(this).focus(function() { | |
$(_label).addClass("focus"); | |
}); | |
$(this).blur(function() { | |
$(_label).removeClass("focus"); | |
}); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment