Search code examples
javascripthtmljquerycssstyles

Set custom style attribue doesn't work in IE11


I have this simple Javascript code to change custom CSS attribute

var root = document.documentElement;
root.style.setProperty("--custom-bg", "#4f5357");

This works fine in Firefox Google Chrome but it doesn't work in IE 11 also tried

root['--custom-bg'] = "#4f5357";
root.attr("--custom-bg", "#4f5357");
root.style['--custom-bg'] = "#4f5357";

none of them worked .


Solution

  • IE11 doesn't support css custom properties, therefore it doesn't supports this setProperty method.

    Checkout this css-vars-ponyfill, which aims to add basic support.