Is it possible to get the CSSStyleSheet object (document.styleSheets[0]) from a HTMLStyleElement (document.createElement('style')) ?
I would like to dynamically add css rules to a not-inserted-in-the-document-yet <style> element.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can add rules before you add the style element to the document.
A couple notes-
Older IE browsers cannot add child nodes to a style element, so assign to the element’s styleSheet.csstext property for them.
Make sure you append the new element to the head of the document.