How do I make a checkbox toggle from clicking on the text label as well? *

Question

Checkboxes in html forms don't have implicit labels with them. Adding an explicit label (some text) next to it doesn't toggle the checkbox.

Answer

Set the CSS "display" property for the label to be a block element and use that instead of your div - it keeps the semantic meaning of a label while allowing whatever styling you like.

For example

 <label for="test" style="width: 100px; height: 100px; display: block; background-color: #e0e0ff;">
A ticky box! <input type="checkbox" id="test" />
</label>
< br > via < a class="StackLink" href=" http://stackoverflow.com/questions/2123/" >How do I make a checkbox toggle from clicking on the text label as well?< /a>
Share on Google Plus

About Cinema Guy

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment