im пытается создать таблицу стилей с помощью JS и добавить некоторые правила, но это не сработает.Создать Styleshhet и insertRule/addRule
if (style == null) {
var style = document.createElement('style');
style.setAttribute('type', 'text/css');
style.setAttribute('data-style', 13);
if (style.styleSheet) {
style.styleSheet.cssText = '';
} else {
style.appendChild(document.createTextNode(''));
}
document.head.appendChild(style);
}
if (typeof style.insertRule === 'function') {
style.insertRule("main > section[data-y='0']{top: 200px;}");
} else if (typeof style.addRule === 'function') {
style.addRule("main > section[data-y='0']", "{top: 200px;}");
}
Извините im new in Js.
Может кто-нибудь сказать мне, почему это не работает?