According to this, the style tag can be turned off using the disabled
attribute. I attempted the following:
<head>
<style>body { color: black; }</style>
<style disabled>body {color: red; }</style>
</head>
<body>
Hello World !!
</body>
Both Chrome and Firefox ignore the disabled
attribute and display the text in red. However, IE 11 correctly displays it in black.
Query: How can internal style nodes be added in a disabled state using JavaScript?
Background:
I am dynamically loading CSS file content as a style node for processing rules with document.styleSheets.cssRules
. I want to prevent the temporary loaded style from affecting the current page styles.
Although setting document.styleSheets[].disabled
works, there is a delay between node insertion and being disabled.
I experimented with using
new DOMParser().parseFromString(cssFileContent, "text/html")
, which successfully loads the HTML content invisibly, but fails to initialize the document.styleSheets
.