Skip to content

Instantly share code, notes, and snippets.

@deviationist
Last active September 24, 2020 00:46
Show Gist options
  • Select an option

  • Save deviationist/283fda66f3acf7eed76b8d4aa6496222 to your computer and use it in GitHub Desktop.

Select an option

Save deviationist/283fda66f3acf7eed76b8d4aa6496222 to your computer and use it in GitHub Desktop.
A neat JS function that you can use with Ghost Inspector to check if a checkbox/radio button is checked, and it also gives a visual feedback (like the native ones from other checks)
function GI_itemHaveCheckedState(element, state, delay) {
var valid = element.checked === state;
if ( valid ) {
if ( ! delay ) delay = 0;
setTimeout(function() {
element.style.outline = '5px solid rgba(98, 191, 103, 1)';
setTimeout(function() {
element.style.outline = 'initial';
}, 500);
}, delay);
}
return valid;
}
// Usage
return GI_itemHaveCheckedState(document.getElementById('checkbox-1'), true);
return GI_itemHaveCheckedState(document.getElementById('checkbox-2'), false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment