Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Plain JavaScript radioClass Fn
/* adapted from Ext Core radioClass */
function hasClass(el, cls) {
return new RegExp("(^|\\s)" + cls + "(\\s|$)").test(el.className);
}
function addClass(el, cls) {
if (!hasClass(el, cls)) {
el.className += el.className ? " " + cls : cls;
}
}
function removeClass(el, cls) {
var rep = el.className.match(" " + cls) ? " " + cls : cls;
el.className = el.className.replace(rep, "");
}
function radioClass(el, cls) {
var siblings = el.parentNode.childNodes;
for(var i=0; i<siblings.length; i++) {
if(siblings[i].nodeType == 1) {
removeClass(siblings[i], cls);
}
}
addClass(el, cls);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.