Ticket #8163 (closed bug: duplicate)
Selecting "text" inputs that don't have the "text" attribute explicitly set gives mixed results
| Reported by: | patrickwhalen | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | 1.5.1 |
| Component: | selector | Version: | 1.5 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: | #8039 |
Description
Given this HTML:
<input> <!-- W3C standards default is text --> <br> <input type="text"> <!-- explicit text -->
This selector:
$('input[type="text"]')
...does not select the <input> that does not have its "text" attribute set explicitly.
But this selector (with the :input pseudo selector) does select it:
$(':input[type="text"]')
Tested in Chrome 9 beta on Mac, and Firefox 3.6 on Mac.
Test Case: http://jsfiddle.net/eMENG/1/
Change History
comment:3 Changed 2 years ago by jitter
- Priority changed from undecided to high
- Status changed from new to open
- Component changed from unfiled to selector
- Blocked by 8039 added
- Milestone changed from 1.next to 1.5.1
comment:4 Changed 2 years ago by gnarf
the fix for #8039 would make even $(':input[type=text]') fail... Considering that this bug is actually a failure on the qSA implementation, I'd argue that you should always have type='text' on your inputs... Looking for inputs without a type?? after my fix for #8039 is applied $('input:not([type])') would find inputs without a type attribute defined in the HTML
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

For the W3C standard querySelectorAll method, a selector of "input[type=text]" requires that there be an actual attribute with a type of "text" for a match. The reason that ":input" works is that it is a jQuery selector extension, and so uses the Sizzle Javascript engine rather than querySelectorAll. That extension looks at the element's type *property* which is text by default (and also if the type attribute contains an unrecognized type).
Not sure of the resolution on jQuery's end, but it is bad practice to not specify a type because it will prevent querySelectorAll from working.