Hey all,
I just wrote a little jQuery plugin to create custom checkboxes/radio buttons.
The approach is simple. Wrap a label around the input tags, then hide the input and style the label, thus having a minimal impact on the rest of the markup and no need to write weird event handlers to check/uncheck as the browser will take care of checking the field because of the label’s implicit relationship with the .
There would be scenarios of course where people would already put their input inside of the label, so this plugin would create a nested label in those cases. I’m wondering if there are any adverse accessibility effects to having the labels nested like this.
e.g. starting out code (show both implicit and explicit label relationship methods):
<div class="field">
<label for="cbx-1"><input type="checkbox" id="cbx-1" name="cbx-1" /> Apples</label>
</div>
<div class="field">
<input type="checkbox" id="cbx-2" name="cbx-2" /> <label for="cbx-2">Oranges</label>
</div>
Would get transformed to:
<div class="field">
<label for="cbx-1"><label class="checkable-field checkable-checkbox"><input type="checkbox" id="cbx-1" name="cbx-1"></label> Apples</label>
</div>
<div class="field">
<label class="checkable-field checkable-checkbox"><input type="checkbox" id="cbx-2" name="cbx-2"></label> <label for="cbx-2">Oranges</label>
</div>
And if anyone has any other accessibility issues they see, fee free to bring them up as well
GitHub: http://afterlight.github.com/checkable/
Demo: http://afterlight.com.au/demos/checkable/
Cheers (: