Reputation: 457
How to combine these two parts into one
part 1
if ($('input.border-question').is(':checked')) {
$('.as-hidden').show();
}else {
$('.as-hidden').hide();
}
part 2 for click
$('input.border-question').click(function(){
if($(this).is(":checked")){
$('.as-hidden').show();
}
else if($(this).is(":not(:checked)")){
$('.as-hidden').hide();
}
});
Upvotes: 0
Views: 19
Reputation: 35670
Use toggle():
$('.as-hidden').toggle($('input.border-question').is(':checked'));
$('input.border-question').click(function(){
$('.as-hidden').toggle($(this).is(":checked"));
});
Upvotes: 2