How do I add and remove a class only to selected radio button of a set of radio buttons?
<table class="radioClass" role="set1"><tbody><tr><td><input type="radio" value=" Yes " id="" name="j_id0:j_id37:j_id41"> label for="j_id0:j_id37:j_id41:0"> Yes </label></td><td><input type="radio" value=" No " id="" name="j_id0:j_id37:j_id41"<label for="j_id0:j_id37:j_id41:1"> No </label></td></tr></tbody></table>
$(document).ready(function(){
$("input[type='radio']").click(function(){
var radioValue = $("input:checked").val();
if(radioValue){
//alert("Your are a - " + radioValue);
$("input:checked").toggleClass("checked");
}
});
First remove checked
class from all radio buttons and then add to specific selected one. This is how you can do this:
if(radioValue){
$("input[type='radio']").removeClass("checked");
$(this).toggleClass("checked");
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments