Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

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

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 (6)

comment:1 Changed 8 years ago by dmethvin

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.

comment:2 Changed 8 years ago by addyosmani

#8164 is a duplicate of this ticket.

comment:3 Changed 8 years ago by jitter

Blocked by: 8039 added
Component: unfiledselector
Milestone: 1.next1.5.1
Priority: undecidedhigh
Status: newopen

comment:4 Changed 8 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

comment:5 Changed 8 years ago by dmethvin

Resolution: duplicate
Status: openclosed

comment:6 Changed 8 years ago by dmethvin

Duplicate of #8380.

Note: See TracTickets for help on using tickets.