0

When you click on this button, it will only checkoff the checkbox if you click on the "Hello" text. If you click on the button but not the text, it will not check off the box. How can I make it so no matter where I click on the button, it will check off the box?

<button>
    <label for="myId">Hello</label>
</button>


<input id="myId" type="checkbox" />
uionut351j
  • 27
  • 1
  • 6
  • what exactly are you trying to do? if the hello text is inside the box, wont the both of them be pressed simultaneously if you press the button? – Hisham Bawa May 12 '20 at 02:26

1 Answers1

1

You need to make the label to be full width and height as of the button like so:

<button style="padding: 0;">
    <label style="display: block; padding: 20px;" for="myId">Hello</label>
</button>


<input id="myId" type="checkbox" />

Here is the fiddle: https://jsfiddle.net/hxoqrf7v/

Firman Putra
  • 142
  • 8