Reputation: 44086
<div id="name">
</div>
<input type="checkbox" name="myCB" value="A" />Couldn't find the Venue<br />
I can add an Id or class if i need to
I need to toggle between hide and show the div based on the whether clicked or not
Upvotes: 1
Views: 4222
Reputation: 2367
Try this:
<div id="name">
my div text
</div>
<input type="checkbox" name="myCB" id="myCB" value="A"/>Couldn't find the Venue<br />
<script>
$('#myCB').toggle(function() {
$('#name').hide()
}, function() {
$('#name').show()
});
</script>
Upvotes: 0
Reputation: 14873
Here is ready to use and simple code
$('input[name=myCB]').toggle(function() {
$("#name").hide();
}, function() {
$("#name").show();
});
Upvotes: 0
Reputation: 65284
<input type="checkbox" name="myCB" value="A" class="toggler" cheked="checked" />
and without animation,
$(function(){
$('.toggler').click(function(){
$('div#name').toggle(this.checked);
});
})
this with a little animation
$(function(){
$('.toggler').click(function(){
if (this.checked) {
$('div#name').slideDown();
} else {
$('div#name').slideUp();
}
});
})
Upvotes: 4
Reputation: 4487
given your checkbox ID is myCB:
$("#myCB").click(function(){
if($("#name").is(":visible"))
{
$("#name").hide();
}
else
{
$("#name").show();
}
});
you can also check out the .toggle() function:
Upvotes: 0