Skip to content

Instantly share code, notes, and snippets.

@zackn9ne
Created December 5, 2014 23:07
Show Gist options
  • Select an option

  • Save zackn9ne/ff3cf00281aef1c237c2 to your computer and use it in GitHub Desktop.

Select an option

Save zackn9ne/ff3cf00281aef1c237c2 to your computer and use it in GitHub Desktop.
a script to toggle checkboxes and radial buttons where ie8 complaince is heeded
var customUI = {
toggleChecked: function (labelSelector) {
$(labelSelector).each(function () {
var label = $(this);
var input = label.find("input:first");
if (input.length > 0) {
if (input.get(0).checked) {
label.addClass("checked");
} else {
label.removeClass("checked");
}
}
});
},
initCheckboxes: function () {
$("label.checkbox").each(function () {
var label = $(this);
label.click(function () {
customUI.toggleChecked(this);
});
label.find("input").each(function () {
$(this).change(function () {
customUI.toggleChecked($(this).parents("label:first"));
});
});
customUI.toggleChecked(this);
});
},
initRadioButtons: function () {
$(".radioList").each(function () {
$(this).find("input").each(function () {
$(this).change(function () {
customUI.toggleChecked($(this).parents(".radioList:first").find("label"));
});
});
});
},
init: function () {
customUI.initCheckboxes();
customUI.initRadioButtons();
}
};
$(document).ready(customUI.init);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment