How to dynamically create CSS class in JavaScript and apply?

后端 未结 15 1035
长情又很酷
长情又很酷 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

    There is a light jQuery plugin which allows to generate CSS declarations: jQuery-injectCSS

    In fact, it uses JSS (CSS described by JSON), but it's quite easy to handle in order to generate dynamic css stylesheets.

    $.injectCSS({
        "#test": {
            height: 123
        }
    });
    

提交回复
热议问题