Question

I have a group of radio inputs with associated labels. There is some CSS magic to pretty up the buttons, and this works fine. I need to be able to change the selected attribute of the label.

<input type='radio' id='radio1' name='resolution' value='0' selected />
<input type='radio' id='radio2' name='resolution' value='1' />
<label for='radio1' class='cb-enable selected' ><span>Open</span></label>
<label for='radio2' class='cb-disable ' ><span>Closed</span></label>

How would I go about setting the label selector with jQuery?

Was it helpful?

Solution

$("input:radio[name='resolution']").change(function(){
    $("label").removeClass("selected");
    $("label[for='" + this.id + "']").toggleClass("selected", this.checked);
});

http://jsfiddle.net/QKL5t/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top