Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7034309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:10:12+00:00 2026-05-28T01:10:12+00:00

The sample code uses JQuery to prevent the user from unchecking the last checked

  • 0

The sample code uses JQuery to prevent the user from unchecking the last checked checkbox. It works as expected in Firefox and Chrome, but not in Opera or IE.

<!DOCTYPE html>
<html>
<head>
    <style type="text/css">
        #checkboxContainer label {
            float: left;
            clear: right;
        }
        #checkboxContainer input {
            float: left;
            clear: left;
        }
    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#checkboxContainer input[type='checkbox']").change(function(evt) {
                if ($("#checkboxContainer input[type='checkbox']:checked").length == 0) {
                    console.log("Only 1 checkbox; can't uncheck.");
                    $(evt.target).attr("checked", "checked");
                }
            });
        });
    </script>
</head>
<body>
    <div id="checkboxContainer">
        <input type="checkbox" id="checkbox1" checked="checked"/>
        <label for="checkbox1">1</label>
        <input type="checkbox" id="checkbox2"/>
        <label for="checkbox2">2</label>
    </div>
</body>
</html>

What’s going on here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:10:13+00:00Added an answer on May 28, 2026 at 1:10 am

    This seems to work in IE and Opera if you change your selector to “:checkbox” instead of “input[type=’checkbox’]”. The jQuery docs state that the two are equivalent, so I am not sure how to explain the difference in behavior.

    <script type="text/javascript">
        $(document).ready(function() {
            $("#checkboxContainer :checkbox").change(function(evt) {
                if ($("#checkboxContainer :checkbox:checked").length == 0) {
                    console.log("Only 1 checkbox; can't uncheck.");
                    $(evt.target).attr("checked", "checked");
                }
            });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning about jquery mobile. I came across a sample code which uses
I have seen sample source code around that uses different ways of releasing/dealloc'ing objects,
Here is my sample code: from xml.dom.minidom import * def make_xml(): doc = Document()
Here is a sample code to retrieve data from a database using the yield
I follow some sample code which uses trace(Hello World); to print out something in
Could someone please give me some sample code that uses an output parameter in
I've a simple menu on my page, that uses this jquery code for basic
I'm building an asp.net page that uses a page method call from jquery. This
I've got a simple bit of code that uses BeginTransaction() . The resulting transaction
Sample code that shows how to create threads using MFC declares the thread function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.