public
Created

RadioNodeList polyfill

  • Download Gist
polyfill.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
/*
demo :- http://jsfiddle.net/bjkkD/20/
 
Implements RadioNodeList :- http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#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;
return;
}
}
}
}());

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.