Disable CSS Style in Javascript

Description

The CSSStyleSheet.disabled property lets you enable and disable all of the styles in a stylesheet.

Example


<!DOCTYPE HTML>
<html>
<head>
<style title="core styles">
p {<!--from w ww . j  av a2 s  .c  om-->
  border: medium double black;
  background-color: lightgray;
}

#block1 {
  color: white;
  border: thick solid black;
  background-color: gray;
}
</style>
</head>
<body>
  <p id="block1">
  This is a test. 
  </p>
  <div>
    <button id="pressme">Press Me</button>
  </div>
  <script>
    document.getElementById("pressme").onclick = function() {
      document.styleSheets[0].disabled = !document.styleSheets[0].disabled;
    }
  </script>
</body>
</html>

Click to view the demo





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window