function addClassName(el, newClasses){
    var hasClassList = useClassList && el.classList,
        elClasses    = (el.className||'').split(/\s+/);
    // make sure 'newClasses' is an array
    newClasses = [].concat(newClasses||[]).join(' ').split(/\s+/);
    newClasses.forEach(function(cls){
        if (hasClassList) {
            el.classList.add(cls);
        }
        else {
            // don't add duplicate classes
            if (!hasClassName(el, cls)){
                elClasses.push(cls);
            }
        }
    });
    if (!hasClassList){
        elClasses = elClasses.join(' ').trim();
        // set the new className and return the string
        return el.className = elClasses;
    }
}
// add new element class without destroying existing class
add new element class without destroying existing class
add new element class without destroying existing class
function addClassName(el, newClasses){
    var hasClassList = useClassList && el.classList,
        elClasses    = (el.className||'').split(/\s+/);
    newClasses = [].concat(newClasses||[]).join(' ').split(/\s+/);
    newClasses.forEach(function(cls){
        if (hasClassList) {
            el.classList.add(cls);
        }
        else {
            if (!hasClassName(el, cls)){
                elClasses.push(cls);
            }
        }
    });
    if (!hasClassList){
        elClasses = elClasses.join(' ').trim();
        return el.className = elClasses;
    }
}
function addClassName ( el , newClasses ) { var hasClassList = useClassList && el . classList , elClasses = ( el . className || '' ) . split ( / \s+ / ) ; newClasses = [ ] . concat ( newClasses || [ ] ) . join ( ' ' ) . split ( / \s+ / ) ; newClasses . forEach ( function ( cls ) { if ( hasClassList ) { el . classList . add ( cls ) ; } else { if ( ! hasClassName ( el , cls ) ) { elClasses . push ( cls ) ; } } } ) ; if ( ! hasClassList ) { elClasses = elClasses . join ( ' ' ) . trim ( ) ; return el . className = elClasses ; } }
add new element class without destroying existing class
add new element class without destroying existing class
// make sure 'newClasses' is an array // don't add duplicate classes // set the new className and return the string