Last active
June 19, 2019 14:52
-
-
Save YurePereira/e32cfe9bf5195540a0dbd87be78d6c38 to your computer and use it in GitHub Desktop.
Ways to check if an input Checkbox is checked
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
| var myCheckbox = $('#my_checkbox:checked'); | |
| //Checando com o selector :checked | |
| if (myCheckbox.val()) { | |
| console.log('Checked!'); | |
| } else { | |
| console.log('Not checked!'); | |
| } |
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
| var myCheckbox = $('#my_checkbox'); | |
| //Checando com a função is | |
| if (myCheckbox.is(':checked')) { | |
| console.log('Checked!'); | |
| } else { | |
| console.log('Not checked!'); | |
| } |
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
| //Checando com a propriedade cheched do elemento com JavaScript | |
| var myCheckbox = $('#my_checkbox'); | |
| if (myCheckbox[0].checked) { | |
| console.log('Checked!'); | |
| } else { | |
| console.log('Not checked!'); | |
| } |
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
| var myCheckbox = $('#my_checkbox'); | |
| //Checando com a função PROP | |
| if (myCheckbox.prop('checked')) { | |
| console.log('Checked!'); | |
| } else { | |
| console.log('Not checked!'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment