Set a checkbox as checked or unchecked

The most recommend ways to set a checkbox as checked or unchecked via jQuery or pure JavaScript.


Libraries

Code Snippet
// Pure JavaScript
document.getElementById('myCheckbox').checked = true;  // Checked
document.getElementById('myCheckbox').checked = false;  // Unchecked


// >In jQuery, it's quite the same
$('#myCheckbox').checked = true;  // Checked
$('#myCheckbox').checked = false;  // Unchecked


Implementation

Use a line above to check or uncheck a checkbox with id "myCheckbox".





Comments
  • mode_editWrite a comment



  • forumComments




Embed Code

We provide special containers which include the full snippet and a link to this site. So for example when you make a tutorial and you are using code from this site, you can use one of the following snippet embeddings:

Load Preview Get Code Close Preview







    Share
    Rating
    thumb_up 1 thumb_down
    Author
    Thorolus

    I'm the head developer and co-founder of GlovilGames Studios (glovilgames.com) and other platforms GlovilGames created, like vsnippets.com, worth-calculator.net, python-obfuscator.com and some mobile apps and games.

    Tags
    Checkbox
    Input
    Checked
    Unchecked
    jQuery



    Informations

    posted on 2016-09-13 21:51:48

    viewed 59 times

    snippet's UUID is 57d858d485761

    Similar Snippets