title: Checking if an input field is required using jQuery
body: <p>What would be the easiest way to check if an input is required? I have been trying stuff along these lines but always comes up with all required (only 4/6 are).</p>
  
  <pre><code>$('form#register').find('input').each(function(){
      if($(this).prop('required') == 'undefined'){
          console.log("NR");
      } else {
          console.log("IR");
      }
  })
  </code></pre>
  
  <p>(I have tried .attr aswell)</p>
  
  <p>Im trying to use it for form ajax validation, Im doing it this way at the moment:</p>
  
  <pre><code>if($('form#register span').length == $('form#register').children(".green").length){
      $('input#register-sub').prop('disabled', false);
  } else {
      $('input#register-sub').prop('disabled', true);
  }
  </code></pre>
  
  <p>Thanks.</p>
  
  <p>EDIT: Html adding</p>
  
  <pre><code>&lt;form id="register" action="" method="post" autocomplete="on"&gt;
  &lt;label&gt;Nickname:&lt;/label&gt;&lt;input type="text" name="name" value="&lt;? echo $_POST['name'] ?&gt;" required="" /&gt;&lt;span id="reg-name"&gt;&lt;/span&gt;&lt;br /&gt;
  
  &lt;?  if($user-&gt;type == "l"){ ?&gt;
  &lt;label&gt;email:&lt;/label&gt;&lt;input type="email" name="email" value="&lt;? echo $_POST['email'] ?&gt;" required="" /&gt;&lt;span id="reg-email"&gt;&lt;/span&gt;&lt;br /&gt;
  &lt;label&gt;Password:&lt;/label&gt;&lt;input type="password" name="password" value="&lt;? echo $_POST['password'] ?&gt;" required="" /&gt;&lt;span id="reg-password"&gt;&lt;/span&gt;&lt;br /&gt;
  &lt;label&gt;Again:&lt;/label&gt;&lt;input type="password" name="password-test" value="&lt;? echo $_POST['password-test'] ?&gt;" required="" /&gt;&lt;span id="reg-password-test"&gt;&lt;/span&gt;&lt;br /&gt;
  &lt;label&gt;Avatar:&lt;/label&gt;&lt;input type="url" name="avatar" value="&lt;? echo $_POST['avatar'] ?&gt;" /&gt;&lt;span id="reg-avatar"&gt;&lt;/span&gt;&lt;br /&gt; 
  &lt;? } ?&gt;
  
  &lt;input type="submit" value="Register" disabled="" id="register-sub"/&gt;
  </code></pre>
  
  <p></p>