The right way to make HTML5 checkbox

I can't find an example anywhere ... what's the right way to make an HTML5 checkbox?

+48
html html5
04 Feb '11 at 18:10
source share
2 answers

As far as I know the state of the documents , nothing has fundamentally changed. Basic markup

<input name="your_name" value="your_value" type="checkbox"> 

What's new, some interesting properties.

  • form - a link to the form with which the control is associated (nice!)
  • autofocus - focus as soon as the document is loaded (nice!)
  • required - it needs to be checked (super good! Although it is not supported by Internet Explorer or Safari (for now).)
+73
Feb 04 '11 at 18:13
source share

A more complete example is to avoid a long message flow in How to check if a checkbox is selected in jQuery? .

HTML

 <input id="your_id" name="your_name" value="your_value" type="checkbox"> 

If necessary, add the attribute 'checked', which by default will be set at boot.

 <input id="your_id" name="your_name" value="your_value" type="checkbox" checked> 

Javascript

 $('#your_id').is(':checked') // Returns a Boolean TRUE if checked 

eg.

 if ($('#your_id').is(':checked')) { // Checkbox was checked } 
+4
Feb 21 '14 at 15:32
source share



All Articles