I want to check that if the checkbox is checked, for example, paint a paragraph yellow, and if I disable it, I don't understand how to make it work, I have this code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<input type="text" id="num1">
<input type="text" id="num2">
<input type="checkbox" id="checkbox">
<p id="color">Test</p>
<script>
if ($('#checkbox').prop('checked')) {
$('#color').css('background','yellow');
}
</script>
</body>
</html>
Friend, to detect changes in your checkbox use the property
checked
and with that it askscheckbox
if it is checked .this should work
You use the on click method to hear the change.