I am aware that in JQuery - find a radio button by value is simply
$(":radio[value=foobar]")
How would I use Javascript to find a radio button by its value?
I am aware that in JQuery - find a radio button by value is simply
$(":radio[value=foobar]")
How would I use Javascript to find a radio button by its value?
If requirement is to not use jQuery, you can use document.querySelector()
with multiple attribute selector
document.querySelector("input[type=radio][value=foobar]")
You can do something like this:
document.querySelector("input[type='radio'][value='foobar']");
I assume you meant a non-jQuery way, as jQuery is Javascript :)
A naïve approach would be to filter input elements, determine if it's a radio button and determine the value:
var inputs = document.getElementsByTagName('input');
var radios = inputs.filter(function(el) {
return el.type == 'radio';
};
var valueRadios = radios.filter(function(radio) {
return radio.value == 'foobar';
};