JavaScript: how to add CSS style tag with settings to DOM
2020-01-13 2020-01-26 20:04:46 Javascript,jQuery,CSS
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);