Using a checkbox, I want to change the checked state of two radio buttons. This works fine, but when changing the checkbox again, the radio button checked visual 'disappears' while the code shows it is checked. How does this come?
Demo: http://jsfiddle.net/Tz99c/
JS:
$("#change_radio").change(function () {
if ($(this).is(":checked")) {
$("#one").attr("checked", false);
$("#two").attr("checked", "checked");
}
else {
$("#two").attr("checked", false);
$("#one").attr("checked", "checked");
}
});
HTML:
<input type="radio" id="one" name="test" checked="checked"><label for="one">one</label>
<input type="radio" id="two" name="test"> <label for="two">two</label>
<input type="checkbox" id="change_radio"> <label for="change_radio">check</label>