title: Applying a CSS style using JavaScript if text field is empty
body: <p>I have this function in JavaScript which I called using an onclick event in my HTML code:</p>
  
  <pre><code>function checkTextField(field) {
  if (field.value == '') {
      sheet.insertRule("input:focus {background: #fc9fff;}", 1);
    }
  }
  </code></pre>
  
  <p>I've checked that the if statement works by using an alert statement within it instead of the insertrule, but it seems that the css is applied even though the value of the field is not empty. Is there anything else I can use?</p>