jquery - disable all the radio button with same name -
i have 2 set of radio button, if 1 of option selected other radio in same group have disabled.
<div class="question_container"> <p class="questions">question stuff?</p> <span class="group" style="inline-block;"> <label> <input id="id_radio1" class="incorrect" type="radio" name="group1" value="answer 1" />answer 1 </label> <label> <input id="id_radio2" class="correct" type="radio" name="group1" value="answer 2" />answer 2 </label> <label> <input id="id_radio3" class="incorrect" type="radio" name="group1" value="answer 3" />answer 3 </label> <label> <input id="id_radio4" class="incorrect" type="radio" name="group1" value="answer 4" />answer 4 </label> </span>
question stuff? answer 1 answer 2 answer 3 answer 4 $("input[type=radio]").click(function () { var radio = $(this); var getgroup = radio.parents(".group"); getgroup.find("label").css({ "background-color": "transparent" }); if (radio.attr("class") == 'correct') { radio.parent().css({ "background-color": "green" }); } else radio.parent().css({ "background-color": "red" });
});
var radioname = radio.attr('name'); $("input[name='" + radioname + "']").attr("disabled","disabled");
Comments
Post a Comment