Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
16
rated 0 times [  17] [ 1]  / answers: 1 / hits: 97363  / 12 Years ago, thu, february 7, 2013, 12:00:00

I am trying to hide div when user clicks on checkbox, and show it when user unchecks that checkbox.
HTML:



<div id=autoUpdate class=autoUpdate>
content
</div>


jQuery:



<script>
$('#checkbox1').change(function(){
if (this.checked) {
$('#autoUpdate').fadeIn('slow');
}
else {
$('#autoUpdate').fadeOut('slow');
}
});
</script>


I am having a hard time to get this working.


More From » jquery

 Answers
22

Make sure to use the ready event.



Code:



$(document).ready(function(){
$('#checkbox1').change(function(){
if(this.checked)
$('#autoUpdate').fadeIn('slow');
else
$('#autoUpdate').fadeOut('slow');

});
});

[#80366] Wednesday, February 6, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devlin

Total Points: 474
Total Questions: 113
Total Answers: 100

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
devlin questions
Tue, Apr 27, 21, 00:00, 3 Years ago
Sat, Oct 31, 20, 00:00, 4 Years ago
Fri, Aug 28, 20, 00:00, 4 Years ago
;