SASHI
SASHI

Reputation: 199

Using jQuery, show a div if only two or more checkboxes are checked

I need to show a div if two or more checkboxes are checked using JQuery only.

How can I achieve this?

Upvotes: 0

Views: 815

Answers (2)

Adam
Adam

Reputation: 44939

jQuery:

$('input[type=checkbox]').change(function(){
        if($('input:checked').size() > 1){
         $("div").show();   
    }
    else {
         $('div').hide()   
    }
})

HTML:

<input type="checkbox" id="one"></input>
<input type="checkbox" id="one"></input>
<input type="checkbox" id="one"></input>
<div style="display: none;">At least 2 are checked</div>

Try it!

Upvotes: 2

John Strickler
John Strickler

Reputation: 25421

if($('input:checked').length >= 2) {
   $('div').show();
}

Upvotes: 2

Related Questions