Why does the button toggle the checkbox?

  • 0
    When you click on the checkbox, a form submit button appears. But by clicking on it, instead of submitting the form, it switches the checkbox state.
    Tell me how to fix it.
    JavaScript Anonymous, Mar 1, 2019

  • 2 Answers
  • 0
    Because your button lies inside the label, next to the checkbox. When you press the button, it turns out that you press the label, the checkbox switches accordingly. Either add the button somewhere outside the label, or intercept the event, see what was clicked, and if the button is clicked, do submit.

    Personally, the first option seems more correct to me.
    Xander Garner

  • 0
    Because you have a class chackbox, you have display: block; stretches to full width.

    You need to raise the button somehow above the block. We need to work with the z-index of the button and the checkbox.
    Delilah McGuire

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!