css - how to get a CSSStyleSheet object from a <style> -
one < style > corresponding 1 cssstylesheet object (in document.stylesheets), how find it, such cssstylesheet object corresponding < style id="-ycoder-styles" >...< /style>
console.log(document.stylesheets.length); var style = document.createelement('style'); style.title = "-ycoder-styles"; style.type= 'text/css'; style.id = "-ycoder-styles"; document.head.appendchild(style); //how corresponding cssstylesheet instance document.stylesheets console.log(document.stylesheets.length); var stylesheet = document.stylesheets[document.stylesheets.length - 1]; console.log(stylesheet.title == style.title);
based on code provided, should able associated cssstylesheet with:
var stylesheet = style.sheet
this work after <style>
element has been appended document.
not exceptionally documented , difficult find poking around in console.
Comments
Post a Comment