Style aus Stylesheet verändern#
function findStyle(selectorText) { for (var i = 0; i < document.styleSheets.length; ++i) { var styleSheet = document.styleSheets[i]; var css = styleSheet.cssRules || styleSheet.rules; for (var j = 0; j < css.length; ++j) { var rule = css[j]; if (rule.selectorText == selectorText) return rule.style; } } }
Die Funktion kann dann wie folgt verwendet werden:
findStyle('.test').width = '100px';