To disable <style>
blocks, all browsers allow setting document.styleSheets[x].disabled = true
. However, only IE allows this property to be set on the tag itself, <style disabled="true">
. Is there a workaround for this in other browsers? It seems odd that something done dynamically can't also be done statically.
The style
element has no valid attribute named disabled
. From the HTML spec:
<!ELEMENT STYLE - - %StyleSheet -- style info -->
<!ATTLIST STYLE
%i18n; -- lang, dir, for use with title --
type %ContentType; #REQUIRED -- content type of style language --
media %MediaDesc; #IMPLIED -- designed for use with these media --
title %Text; #IMPLIED -- advisory title --
>
However, the HTMLStyleElement
DOM interface does have such a property. From the DOM spec:
interface HTMLStyleElement : HTMLElement {
attribute boolean disabled;
attribute DOMString media;
attribute DOMString type;
};
Don't confuse an HTML element with its counterpart in the DOM. It is not "odd that something done dynamically can't also be done statically." The HTML and DOM specs were created to solve different problems. HTML is a markup language. The DOM is a convention for representing and interacting with the objects in a document.
Extending on the media
answer by @lampyridae, you can negate a media selector using not
. To disable a style tag statically, I use media="not all"
, which works for me in Chrome 79.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With