How to dynamically create CSS class in JavaScript and apply?

后端 未结 15 1009
长情又很酷
长情又很酷 2020-11-22 02:57

I need to create a CSS stylesheet class dynamically in JavaScript and assign it to some HTML elements like - div, table, span, tr, etc and to some controls like asp:Textbox,

15条回答
  •  旧巷少年郎
    2020-11-22 03:41

    Using google closure:

    you can just use the ccsom module:

    goog.require('goog.cssom');
    var css_node = goog.cssom.addCssText('.cssClass { color: #F00; }');
    

    The javascript code attempts to be cross browser when putting the css node into the document head.

提交回复
热议问题