Andrey Shandrov
Andrey Shandrov

Reputation: 457

jQuery combine two parts

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

Answers (1)

Rick Hitchcock
Rick Hitchcock

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

Related Questions