Setting – Stephen P Mar 17 '16 at 00:19

  • There is something not right. The mdn link, earlier, says "disabled" is true if it's enabled and false if it's not which implies, to me, this is a read only attribute. It's also under Web APIs. I'm not sure this is valid HTML markup here. In fact, the validator flags it as an error. – Rob Mar 17 '16 at 03:54
  • I'm voting to close this question as off-topic because the problem is about invalid HTML attributes. – Rob Mar 17 '16 at 03:56
  • 1 Answers1

    1

    Try this:

     <style id="switch">
     body{ 
        background-color: gray;
     }
     </style>
    
     <script>
     $(document).ready(function(){
         $('.button').click(function(){
            document.getElementById("switch").disabled=true;
        });
     });
     </script>
    
    <html>
        <body>
        <a href="#" class="button"><button>Button</button></a>
        </body>
    </html>
    

    Setting an id to the style tag will control specific css. You can re-enable it by changing disabled back to false. Hope that works.

    TMKAB121
    • 276
    • 2
    • 8
    • Can you provide a citation for this? I never knew disabling a style element would turn its rules off! – Stephen P Mar 17 '16 at 00:08
    • 1
      @StephenP See [HTMLStyleElement.disabled](https://www.w3.org/TR/html5/document-metadata.html#dom-style-disabled), [LinkStyle.disabled](https://www.w3.org/TR/html5/document-metadata.html#dom-linkstyle-disabled) and [StyleSheet.disabled](https://www.w3.org/TR/DOM-Level-2-Style/stylesheets.html#StyleSheets-StyleSheet-disabled). – Oriol Mar 17 '16 at 13:12
    • Sorry I didn't have a reference on hand. I've used this trick long ago to force off css for print mode. It also works on external css files. [w3schools](http://www.w3schools.com/jsref/prop_html_disabled.asp) see example 2. – TMKAB121 Mar 17 '16 at 15:23