Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Can anyone tell me how to check/uncheck checkbox using JavaScript?

1 Answer

0 votes
by (19.7k points)

Please check the code below:

JavaScript code: 

// Check

document.getElementById("checkbox").checked = true;

// Uncheck

document.getElementById("checkbox").checked = false;

JQuery(versions above 1.6+): 

// Check

$("#checkbox").prop("checked", true);

// Uncheck

$("#checkbox").prop("checked", false);

For JQuery versions below 1.5- : 

// Check

$("#checkbox").attr("checked", true);

// Uncheck

$("#checkbox").attr("checked", false);

Interested in Java? Check out this Java tutorial by Intellipaat. 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...