Instantly share code, notes, and snippets.

Embed
What would you like to do?
Update Switchery toggle-switch to reflect checkbox state via Javascript
// Manually trigger a change event on a checkbox element to have Switchery update its toggle state
// https://github.com/abpetkov/switchery/issues/27
// http://jsfiddle.net/3am89/
function onChange(checkboxEl) {
if (typeof Event === 'function' || !document.fireEvent) {
var event = document.createEvent('HTMLEvents');
event.initEvent('change', true, true);
checkboxEl.dispatchEvent(event);
} else {
checkboxEl.fireEvent('onchange');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment