It's Possibile Select One Radio Without Name Attribute?
I need to use attribute name so I can use 'name' attribute for radio button. I know that the code for radio button with exclusive choice is:
Solution 1:
you could use a class
:-
$('.radio').change(function() {
$('.radio').not(this).prop('checked', false);
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="radio"class="radio"><inputtype="radio"class="radio">
or even just by the type
:-
var radios = $('[type="radio"]');
radios.change(function() {
radios.not(this).prop('checked', false);
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="radio"><inputtype="radio">
Solution 2:
I suggest something similar to @BG101 but wrap it in a function and allow any jQuery selector to be used so you could target multiple groups.
https://jsfiddle.net/53knnzho/
functionbindRadios(selector){
$(selector).click(function() {
$(selector).not(this).prop('checked', false);
});
};
bindRadios("#radio1, #radio2, #radio3");
bindRadios("#radio4, #radio5, #radio6");
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype='radio'id='radio1' /><inputtype='radio'id='radio2' /><inputtype='radio'id='radio3' /><br><br><inputtype='radio'id='radio4' /><inputtype='radio'id='radio5' /><inputtype='radio'id='radio6' />
Post a Comment for "It's Possibile Select One Radio Without Name Attribute?"