Just use below code for following purpose
- How to show/hide an element on checkbox checked/unchecked states using jQuery?
- jquery show-hide div based on checkbox value
- If checkbox is checked show div
- on checkbox checked show div jquery
- How to show and hide input fields based on checkbox selection
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>How to show/hide an element on checkbox checked/unchecked states using jQuery?</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function myFunction() {
var checkBox = document.getElementById("cwebsite");
var text = document.getElementById("cwimg");
if (checkBox.checked == true){
text.style.display = "block";
} else {
text.style.display = "none";
}
}
</script>
</head>
<body>
<form>
<h3>Select your favorite sports:</h3>
<input type="checkbox" value="1" onclick="myFunction()" id="cwebsite" class="form-control" name="cwebsite" >
<img src="" id="cwimg">
</form>
</body>
</html>