Show/hide Div When Checkbox Selected
I need to make additional content appear when a user selects a checkbox. I have the following code: Checkbox
Solution 1:
You are missing jQuery in your head you must include it.
<scriptsrc="http://code.jquery.com/jquery-1.9.1.js"></script>
Your code works DEMO
Update according to new info
$(document).ready(function () {
$('#checkbox1').change(function () {
if (!this.checked)
// ^
$('#autoUpdate').fadeIn('slow');
else
$('#autoUpdate').fadeOut('slow');
});
});
You can also just use .fadeToggle()
$(document).ready(function () {
$('#checkbox1').change(function () {
$('#autoUpdate').fadeToggle();
});
});
Solution 2:
first in head include jquery
<scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script><scripttype="text/javascript">
$(document).ready(function(){
$('#checkbox1').change(function(){
if($(this).is(":checked"))
$('#autoUpdate').fadeIn('slow');
else
$('#autoUpdate').fadeOut('slow');
});
});
</script>
see demo
Solution 3:
Plese replace your code with below it will help you
<!DOCTYPE html><html><head><title>Checkbox</title><scriptsrc="http://code.jquery.com/jquery-1.9.1.js"></script><scripttype="text/javascript">
$(document).ready(function(){
$('#checkbox1').change(function(){
if(this.is(":checked") == true)
$('#autoUpdate').fadeIn('slow');
else
$('#autoUpdate').fadeOut('slow');
});
});
</script></head><body>
Add another director <inputtype="checkbox"id="checkbox1"/><divid="autoUpdate"class="autoUpdate">
content
</div></body></html>
Post a Comment for "Show/hide Div When Checkbox Selected"