Last active
September 24, 2020 00:46
-
-
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)
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
| 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