SoFunction
Updated on 2025-03-10

JavaScript dynamically add style nodes

This article describes the method of dynamically adding style nodes in JavaScript. Share it for your reference. The details are as follows:

var css = 'h1 { background: red; }',
head = ('head')[0],
style = ('style');
 = 'text/css';
if(){
 = css;
}else{
((css));
}
(style);

I hope this article will be helpful to everyone's JavaScript programming.