jquery - Custom styled checkboxes - problem with my JavaScript logic (an else branch is not getting hit) -
I am creating some custom "checkboxes" and what does it mean that I only styling the labeling elements Position the checkbox from the screen. It was the design / functionality which had come, so I thought I wanted to go it using the Mean checkbox.
What do I want when you click on one of these custom "checkboxes" (to actually trigger the stylized label), "checkbox" should change the color and all the "checkboxes" Behind the background divisions should also be "light". I have got all this work.
When you uncheck the "checkbox", the "checkbox" is undeclared, but you are marked any "checkbox". When you uncheck that last "checkbox", then and should close that background div color this is where I have problems . The best image with the example! I have a console statement and if you see them, you will see that when I close the last checkbox I am not executing that third branch. I just keep track of checked state and using a simple counter that how many "checkboxes" are checked. Anyone have any ideas? Since this is only the There is even a small number of code where you do not need to keep track of the count, can be further customized, but basically I just check whether Any input is checked within the parent Onchange is counting at least 1, so it was never 0, so the third branch was never called. Or better explanation, if there is no untoward, to check the HAD first, the count on the last call should start at 1. I have moved my condition right now in the second position, because it is where you are unchecked, at that time you see that they are all uncontrolled.
$ (function () {var $ help_choices = $ ('#help_choices'), count = 0; console.log (count); $ ('input: checkbox', $ help_choices) .change (function () {var check = this.checked, $ label = $ (this) parent (); if (check) {// plus checkbox, one or multiplier $ help_choices.addClass ('help_choices_selected') Check; $ labels.claims ('help_label_selected'); count ++; console.log (checked + "+ count);} Else {// subtractive checkboxes, un or check multiples count-- $ label .removeClass ('help_label_selected'); // Enter the last check here (count === 0) {$ help_choices.removeClass ('Help_choices_selected'); $ label .removeClass ('help_label_selected'); console.log (Czech + '' + Count + 'arrow Branch ');}}});});
input: check on the
#help_choices element.
$ (function () {var $ help_choices = $ ('# help_choices'); $ ('Input: checkbox', $ Help_choices) .change (function () {var check = this.checked, $ label = $ (this) .Parent (), if (checked) {// plus checkbox, one or multiplier $ help_choices.addClass (' $ Label.addClass ('help_label_selected');} Other {// subtractive checkbox, uncheck one or multiplier $ Label.removeClass ('help_label_selected'); if ($ ('# help_choices input: check' ). Length === 0) {$ help_choices.removeClass ('help_choices_selected');}}});});
Comments
Post a Comment