- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set “checked” for a checkbox with jQuery?
Use the checked attribute to set the checkbox with jQuery. Also, the prop() method is used to get the property value.
Example
You can try to run the following code to learn how to set checked for a checkbox:
<!DOCTYPE html> <html> <head> <title>jQuery Example</title> <style> b { color: green; } </style> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> </head> <body> <input id="checkbox1" type="checkbox" checked="checked"> <label for="checkbox1">Check/ Uncheck this checkbox</label> <p></p> <script> $( "input" ).change(function() { var $input = $( this ); $( "p" ).html( ".attr( \"checked\" ): <b>" + $input.attr( "checked" ) + "</b><br>" + ".prop( \"checked\" ): <b>" + $input.prop( "checked" ) + "</b><br>" + ".is( \":checked\" ): <b>" + $input.is( ":checked" ) + "</b>" ); }).change(); </script> </body> </html>
- Related Articles
- How do I check whether a checkbox is checked in jQuery?
- How to check whether a checkbox is checked with JavaScript?
- How to handle when checkbox 'checked state' changed event in jQuery?
- How to disable/ enable checkbox with jQuery?
- How to check whether a checkbox is checked in JavaScript?
- How to write a jQuery selector for the label of a checkbox?
- HTML DOM Input Checkbox checked Property
- jQuery :checked Selector
- jQuery :checkbox Selector
- How to change a specified cell value or color when checkbox is checked in Excel?
- How to set new id attribute with jQuery?
- JavaFX example to set action listeners to a CheckBox
- How to set new value for an attribute using jQuery?
- How to create a listView with a checkBox in Kotlin?
- How to get and set form element values with jQuery?

Advertisements