Code customizer

by Ryan Perez

HTML

<p>Ryan</p>

CSS

.brand-color-primary {color:red}

JavaScript

//These will be your classes
// Available options are "ALL", "SOME", "1
var  primaryClass = ["brand-color-primary", "brand-color-secondary", "brand-color-tertiary"]
var indices = [0,2];

function changeColor(e, numClasses, indices){
    <!-- primaryClass is an array of classnames-->
    var classNames = "";
    
    switch(numClasses) {
        case "ALL":
            classNames += primaryClass.join(" ");
            break;
        case "SOME":
            var selectedClassNames = [];
            for (var i = 0; i< indices.length; i++) {
                selectedClassNames.push(primaryClass[indices[i]]);
            }
            classNames += selectedClassNames.join(" ");
            break;
        case "1":
            var specifiedIndex = indices[0];
            classNames += primaryClass[specifiedIndex];
            break;
        default:
            break;
    }
    
    $(e).addClass(classNames);

};


// To add all the classes
//changeColor("p", "ALL" );

// To add some of the classes, say the first and second class in the list
changeColor("p", "SOME", [0,1]);

// To add only one class, as well as the position of the class to add
//changeColor("p", "1", [0]);