Dynamically add css to page via javascript

前端 未结 5 1553
旧巷少年郎
旧巷少年郎 2020-12-04 16:33

I\'m making a widget that will be added to external websites, and I have made a page that generates css for them to style it (text color, background color, font size, etc).

5条回答
  •  盖世英雄少女心
    2020-12-04 16:57

    I have traditionally appended a "; $("head").append(style);

    An important thing to note is that because you don't know what any of the existing styles is, or what id's might conflict on the page, it's very useful to keep track of your id's inside your JavaScript application, then using those to populate the injected