JavaScript: how to add CSS style tag with settings to DOM

2020-01-13 00:00:00 IN1 , 2023-04-10 14:16:30 IN1


Native JS

oStyleAppend = function (content) {
    oStyle = document.createElement('STYLE');
    oStyle.type = 'text/css';
    oStyle.appendChild(document.createTextNode(content));
    document.head.appendChild(oStyle);
}

oStyleAppend('.example {height: 100px;}');

jquery

$('<style>').text('.example {height: 100px;}').appendTo(document.head);
This website uses Cookies to provide you with the best possible service. Please see our Privacy Policy for more information. Click the check box below to accept cookies. Then confirm with a click on "Save".