Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
RadioNodeList polyfill
demo :-
Implements RadioNodeList :-
Implementation just adds `.value` as a property to `NodeList`.
Requires ES5 shim and ES5 shimmable browser. (Modern and IE8)
;(function () {
Object.defineProperty(NodeList.prototype, "value", {
get: getRadioNodeListValue,
set: setRadioNodeListValue,
configurable: true
function getRadioNodeListValue() {
for (var i = 0, len = this.length; i < len; i++) {
var el = this[i];
if (el.checked) {
return el.value;
function setRadioNodeListValue(value) {
for (var i = 0, len = this.length; i < len; i++) {
var el = this[i];
if (el.checked) {
el.value = value;
tremby commented Sep 13, 2016

For IE11 I had to change this to define the property on HTMLCollection instead of NodeList, since myform.elements.myradiosetname returns an HTMLCollection rather than a NodeList.

Any comments on that? When would you have a NodeList instead?

I also wrapped it in a conditional: if (typeof RadioNodeList === "undefined") { so it doesn't run where browsers support RadioNodeList.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment