Scot Ranney • August 15, 2024
Clicking on the text next to a checkbox should always check the box, but if you can't use FOR
in the label tag to point to the checkbox input ID
, there is a simple hack to get around this. Simply put everything you inside the label tag, including the input.
In these example, clicking on the text, images, etc, will cause the checkbox to be checked.
<label>
Click me to check the box. <input type="checkbox">
</label>
<label>
<input type="checkbox">
Click me or this image <img src="image.png"> to check the box.
</label>
Etc.