Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#8565 closed bug (duplicate)

'input:text' selector not finding input elements with no type attribute

Reported by: fasteater Owned by:
Priority: undecided Milestone: 1.next
Component: unfiled Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:


As recently as 1.4.3 $('input:text') would find input elements with no type attribute (type=text is the default if no type is defined), but after upgrading to 1.5.1 that is no longer the case.

FYI - this is the selector I now have to use: $('input:text, input:not([type])')

This repros for me in FF3.6 and Chrome 10.0.648.134. IE7 and IE8 work as expected (for a change).

Test case: http://jsfiddle.net/KJL8q/

Change History (5)

comment:1 Changed 12 years ago by fasteater

This is my proposed fix to the text filter (line 3920):

text: function( elem ) {
			// IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc) 
			// use getAttribute instead to test this case
			return "text" === elem.getAttribute( 'type' ) || elem.getAttribute( 'type' ) === undefined;

comment:2 Changed 12 years ago by addyosmani

Although this is a relatively minor fix, in my opinion this is a case of invalid input = invalid output. If people wish to use input elements correctly a valid type should definitely be specified.

comment:3 Changed 12 years ago by anonymous

While I agree that specifying the type is best-practice, it is not invalid to not list it. In fact, the HTML spec doesn't define the type attribute as required, only that type defaults to "text" (something that jQuery relies on for newer HTML5 types in older browsers).

comment:4 Changed 12 years ago by dmethvin

Resolution: duplicate
Status: newclosed

The problem is that the W3C specifies that if the type is not understood by the browser then it defaults to text. So if you have <input type="number" /> it will have a type *property* of number in HTML5-aware browsers but text in non-HTML5 browsers like IE8 or Firefox 3.

There is a fix going into 1.5.2 that will address the specific issue here, but I still think that explicitly specifying a type *attribute* is strongly recommended.

comment:5 Changed 12 years ago by dmethvin

Duplicate of #8380.

Note: See TracTickets for help on using tickets.