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';
<input onkeypress="alert((event || window.event).keyCode);">
<div tabindex="0" onkeypress="alert((event || window.event).keyCode);" onmouseover="focus();" onmouseout="blur();"> TEST </div>