Skip to main content

Bug Tracker

Side navigation

#8163 closed bug (duplicate)

Opened February 03, 2011 03:55PM UTC

Closed February 28, 2011 06:44PM UTC

Last modified February 28, 2011 06:44PM UTC

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:
Blocked by: Blocking:
Description

Given this HTML:

#!xml
<input> <!-- W3C standards default is text -->
<br>
<input type="text">  <!-- explicit text -->

This selector:

#!js
$('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:

#!js
$(':input[type="text"]')

Tested in Chrome 9 beta on Mac, and Firefox 3.6 on Mac.

**Test Case:** http://jsfiddle.net/eMENG/1/

Attachments (0)
Change History (6)

Changed February 03, 2011 04:15PM UTC by dmethvin comment:1

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.

Changed February 03, 2011 04:46PM UTC by addyosmani comment:2

#8164 is a duplicate of this ticket.

Changed February 03, 2011 06:16PM UTC by jitter comment:3

blockedby: → 8039
component: unfiledselector
milestone: 1.next1.5.1
priority: undecidedhigh
status: newopen

Changed February 17, 2011 11:15AM UTC by gnarf comment:4

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

Changed February 28, 2011 06:44PM UTC by dmethvin comment:5

resolution: → duplicate
status: openclosed

Changed February 28, 2011 06:44PM UTC by dmethvin comment:6

Duplicate of #8380.