Source Code: (back to article)
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
</head>
<body>
<button type="button" class="add-attr">Select Checkbox</button>
<input type="checkbox">
<script>
$(document).ready(function() {
$(".add-attr").click(function() {
$('input[type="checkbox"]').attr("checked", "checked");
alert('Checked!');
});
});
</script>
</body>
</html>