Check / uncheck the box without using JavaScript / jQuery
Is it possible to toggle the state (check / uncheck) of a type input checkbox without using JavaScript / jQuery, i.e. only via HTML and CSS?
Let's say I want to toggle it by clicking on the label next to it.
If so, how can we achieve this?
If you need to check / uncheck an input <label>
, check the id
input and use the label for
attribute to connect them.
Another option is to use the label as the container for the input:
See this answer to the question before updating it!
Only using a hardcoded attribute checked
:
<input type="checkbox" checked />
If you want to call it from code, it's not possible without JS / jQuery.
shortcut and input are for collaboration :)
see: https://www.w3.org/wiki/HTML/Elements/label
A signature can be associated with a specific form control:
Usage for attribute [Example A]
By placing the form control inside the label element itself. [Example B]
Yes, you can. Use this code
<label for="MyCheckBox">Click Me !</label>
<input type="checkbox" id="MyCheckBox" />