Javascript Style How to - Style disabled element with Javascript








Question

We would like to know how to style disabled element with Javascript.

Answer


<!DOCTYPE html>
<html>
<head>
<style>
input[disabled] {<!--   www  . java  2 s  .c o m-->
  background: yellow;
}
</style>
</head>
<body>
  <input id="foo" type="text">
  <script>
        document.getElementById('foo').disabled = true;
    </script>
</body>
</html>

The code above is rendered as follows: