Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Checkbox checked an unchecked in jquery and javascript

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 343
    Comment on it

    Hello guys,
    If you want to check and unchecked the checkbox in javascript and jquery use the below code.
    For example :

    Checkbox: <input type="checkbox" id="checkboxid" class ='checkboxclass'>
    


    Checked and unchecked to checkbox in javascript :

     document.getElementById("checkboxid").checked = true;
    
      document.getElementById("myCheck").checked = false;
    

    Checked and unchecked to checkbox in JQuery :
    jQuery 1.6+
    Best way for checked and unchecked by "prop" function in this version.

    $('.checkboxclass').prop('checked', true);
    $('.checkboxclass').prop('checked', false);
    

    jQuery 1.5.x and below
    Best way for checked and unchecked by "attr" function in this version.

    $('.checkboxclass').attr('checked', true);
    $('.checkboxclass').attr('checked', false);
    

    Remove checked from checkbox :

    $('.checkboxclass').removeAttr('checked');
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: