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

  • SEARCH
  • Home
  • 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 993019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:21:20+00:00 2026-05-16T06:21:20+00:00

I am facing a strange behaviour in jQuery 1.4 with the click event. The

  • 0

I am facing a strange behaviour in jQuery 1.4 with the click event. The idea is to click on a drop-down list (change()), which then invert twice a collection of checkboxes by using the click() function of them.
If I have to do so it is because the click on checkboxes update other fields, so I thought instead of inverting the checkboxes checked attribute, let’s just call twice the click on all checkboxes.

Although all the checkboxes are correctly inverted twice, the .length I’m using on the click function looses the right count during the operation, and everytime returns 1 more than it should.

To make it clear here’s the idea of the code:

//The 'click' function
$('input:checkbox').click(function(){
    $(this).parent().find("input:checkbox:checked").length;//<- this one's not returning the right count
    //some code updating other fields thanks to the 'length' of the checkboxes
});

//The dropdown function
$('select.dropdown').change(function(){
    $(this).parent().find("input:checkbox").click();//Invert the first time
    $(this).parent().find("input:checkbox").click();//Invert a second time
});

When I manually check and uncheck the fields, everything’s working perfectly, it’s just when the dropdown call it that the length count is wrong.

Here are 2 scenarios to explain even more in depth the issue I’m experiencing:

  1. If I choose something from the dropdown (the length fails) and then uncheck and recheck a checkbox, the count is right.
  2. If I add a buggy code at the end of the click() function, it works fine except raising an error on the javascript debugger console. Btw, I cannot keep this solution because another function fails in this case.

Cheers,
Nicolas.

  • 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-16T06:21:21+00:00Added an answer on May 16, 2026 at 6:21 am

    If you want to invert the checked state of a checkbox, you can do this:

    $(this).parent().find("input:checkbox").attr('checked', function(i, sel) {
        return !this.checked;
    });
    

    Note that calling .find("input:checkbox").attr(... will invert all the checkboxes. So if you call it twice, they will be inverted twice, giving you the appearance that nothing happened.


    EDIT:

    If the point is that you just want to trigger the handler, you can use .triggerHandler() which will trigger the click without triggering the default behavior of the element.

    $(this).parent().find("input:checkbox").triggerHandler('click');
    

    http://api.jquery.com/triggerhandler/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm facing kind of a strange issue which is related MD5-Hashes in Java and
I am facing strange problem. I am compiling a MFC application(VS 2008) which uses
I'm facing strange OOP behaviour (IMO) in android and maybe in Java in general...
Last days I was facing a strange behavior calculating date diff with jquery datepicker,
I am facing a strange problem regarding Hooking. I have a procedure which acts
i am facing strange problem i deployed a webservice in EC2 which is up
I am facing a strange behaviour for an .aspx page. I have DataList called
I am facing a strange problem while sorting a list of strings with integer
I'm facing a strange behaviour. I have an derived implementation of an .NET XmlSerializer
here's another strange behaviour I'm currently facing. I have an application deployed on a

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.