JavaScript: impostare proprietà CSS multiple

In JavaScript è semplice impostare i valori delle proprietà CSS.

La soluzione è la seguente:


'use strict';

const css = (el, properties) => {
    if(el === null || !el) {
        return false;
    }
    if(typeof properties !== 'object' || properties === null) {
        return false;
    }
    for(let prop in properties) {
        el.style[prop] = properties[prop];
    }

    return true;
};

Torna su