title: JavaScript for HTML5 required field set up to work in Safari
body: <p>I am using the following script to change the HTML5 <code>required</code> attribute of my <code>input</code> elements. I am wonder whether there is a way to modify this script to make it also work in Safari browsers, since Safari does not support this attribute.</p>
  
  <p>Here is the script: </p>
  
  <pre><code>$(document).ready(function() {
      $_POST = array();
      var elements = document.getElementsByTagName("INPUT");
      for (var i = 0; i &lt; elements.length; i++) {
          elements[i].oninvalid = function(e) {
              e.target.setCustomValidity("");
              if (!e.target.validity.valid) {
                  e.target.setCustomValidity("This field can't be blank");
  
              }
          };
          elements[i].oninput = function(e) {
              e.target.setCustomValidity("");
  
          };
      }
  })
  </code></pre>