In this tutorial we will see how to Check Uncheck Checkbox using JQuery. Jquery method .prop() is used for this purpose.
Table of Contents
HTML Code
HTML Code is given below.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Check Uncheck Checkbox using JQuery</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
<button type="button" onclick='check()'>Check Checkbox</button>
<button type="button" onclick='uncheck()'>Uncheck Checkbox</button>
<input type="checkbox">
</body>
</html>
JQuery Code
JQuery Code is given below, In this code we have used .prop() method to check and uncheck the checkbox element.
<script>
function check(){
$('input[type="checkbox"]').prop("checked", true);
}
function uncheck(){
$('input[type="checkbox"]').prop("checked", false);
}
</script>
Demo
Video Tutorial
Watch video tutorial on how to Check Uncheck Checkbox using JQuery.
Post a Comment