The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

Test if at least one checkbox is checked

Last updated on:

In this example, a submit button is disabled if none of the checkboxes are checked and enabled if at least one is checked.

   <!-- bunch of checkboxes like: -->
   <input type="checkbox" ... >
   <input type="checkbox" ... >

   <!-- submit button, defaults to disabled -->
   <input type="submit" value="submit">

The trick is that you can use .is(":checked") on a jQuery object full of a bunch of elements and it'll return true if any of them are checked and false if none of them are. AND, using .attr() for the disabled attribute with that boolean value will enable/disable that button.

var checkboxes = $("input[type='checkbox']"),
    submitButt = $("input[type='submit']"); {
    submitButt.attr("disabled", !":checked"));

Reference URL


  1. Bakaburg
    Permalink to comment#

    That’s net!

  2. beh
    Permalink to comment#

    elegant solution

  3. r
    Permalink to comment#

    so nice

  4. Jeff
    Permalink to comment#

    Thanks! Exactly what I needed!

  5. Kushal Jayswal
    Permalink to comment#

    can we do the same with UL LI structure, like I use custom selectbox and it will convert SELECT – OPTION Tags to UL – LI, so we will be having

      li class="selected"  

    while clicking on the LI and I want atleast ONE LI has CLASS selected there. And if not there it should give alert and not able to refresh the page.

    Can you help me?

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed