Selector fails on missing type="text" attribute

12 June 2014

Debugging some jQuery, the selector input[type='text'] was refusing to select a text input in the page.

By default the type attribute defaults to text, so visually and functionally, it appears like everything is OK.

jQuery however, won't select it if you specify [type='text'].

  <form>   <input type="text" />   <input type="text" />   <input />   <input type="text" />  </form>  
  console.log($("form input[type='text']").length); // Returns 3 rather than 4  

I'm not sure how I feel about this being a bug or not. Easy enough to fix!

Tested on Chrome 22, 35 and FF15