I know I can get the \"value\" attribute of a radiobutton but I\'m finding it strangely difficult to get the text of the radiobutton.
Consider the example below. It has
I added this answer because previously there was no full solution to the question.
Below code uses two prototype functions from the Array object:
forEach
to add click event listener for each radio node
filter
to retrieve checked radio node
as the RadioNodeList does not have those functionalities build-in.
var rblist = document.getElementsByName("colors");;
[].forEach.call(rblist, function(e) {
e.addEventListener('click', showText, false)
});
function showText() {
var rb = [].filter.call(rblist, function(e) {
return e.checked;
})[0];
console.log(rb.nextElementSibling.innerText);
};