So I have a form. Most of the questions asked on the forms use radio inputs.
I'm going with
<label>Option1 <input type="radio"> </label> <label>Option2 <input type="radio"> </label>
I style the labels using: hover, giving it a subtle change in background to indicate which option you highlight. However, I want the label for the selected option to have a different colored background. Is there a way to do this using CSS, or do I need to go with jQuery? What I want to do is declare the parent (label) style of the marked input field.
After another brainstorming session, I would like to change the parent set of bkg-color fieldset when filling in all the necessary fields. I'm starting to feel that jQuery is the way to go here ..?
[Notes:] Using HTML5 / CSS3 / jQuery. Only needs to be compatible with Chrome or Firefox. This is what needs to be run locally on a laptop, so while it works fine on this computer, I donβt have to worry about compatibility in older browsers, etc. :)
Edit: Decision posted by Nick Carver. A few add-ons for working properly with switches. Posting for completeness:
$('input[type="radio"]').change(function() { var tmp=$(this).attr('name'); $('input[name="'+tmp+'"]').parent("label").removeClass("checked"); $(this).parent("label").toggleClass("checked", this.selected); }); $('input[type="checkbox"]').change(function() { $(this).parent("label").toggleClass("checked", this.selected); });
source share