dev4web
2/10/2016 - 2:02 PM

Test for CSS Variables

Test for CSS Variables

function testCSSVariables() {
 var color = 'rgb(255, 198, 0)';
 var el = document.createElement('span');

 el.style.setProperty('--color', color);
 el.style.setProperty('background', 'var(--color)');
 document.body.appendChild(el);

 var styles = getComputedStyle(el);
 var doesSupport = styles.backgroundColor === color;
 document.body.removeChild(el);
 return doesSupport;
}

testCSSVariables();