javascript - how to get a CSSStyleSheet object from a HTMLStyleElement element -
javascript - how to get a CSSStyleSheet object from a HTMLStyleElement element -
is possible cssstylesheet object (document.stylesheets[0]
) htmlstyleelement (document.createelement('style')
) ?
i dynamically add together css rules not-inserted-in-the-document-yet <style>
element.
you can add together rules before add together style element document.
a couple notes-
older ie browsers cannot add together kid nodes style element, assign element's stylesheet.csstext property them. create sure append new element head of document.
function addstyle(css, media1, title1){ var el= document.createelement('style'); el.type= 'text/css'; if(media1) el.media= media1; if(title1) el.title= title1; if(el.stylesheet) el.stylesheet.csstext= css;//ie else{ el.appendchild(document.createtextnode(css)); } //return el without next line if want append later homecoming document.getelementsbytagname('head')[0].appendchild(el); } var cs1= [ '#yw_psq, #yw_psq h2{background-color: green; color: white;}', '#yw_psq_div{margin: 1ex; position: relative; text-align: center;}', '#ps_counter{color: white; margin: 1ex 0 0 0; text-align: center;}', '#pzsq_grid button{cursor: pointer; font-size: 1.2em; width: 100%;}', '#delayspan{font-weight: bold; margin-left: 1em;}' ] addstyle(cs1.join('\n'),'screen','yw_psq');
javascript html css
Comments
Post a Comment