Skip to main content

Bug Tracker

Side navigation

#1169 closed bug (duplicate)

Opened May 11, 2007 04:25PM UTC

Closed February 03, 2010 02:23AM UTC

Selecting a form by ID fails if there's a form value element named "id" [patch]

Reported by: blueyed Owned by:
Priority: major Milestone: 1.1.3
Component: core Version: 1.1.2
Keywords: Cc:
Blocked by: Blocking:

Given a FORM with ID "foo", $("#foo") will fail in Internet explorer (at least IE6) if there's a INPUT named "id". This is because "" will then refer to the (hidden) form field, but not the form's tag attribute "id" itself. It even fails when using getAttribute() explicitly.

I've fixed it like below, checking that is not an object.

Index: jquery/src/selector/selector.js
--- jquery/src/selector/selector.js	(Revision 1883)
+++ jquery/src/selector/selector.js	(Arbeitskopie)
@@ -229,7 +229,8 @@
    // Do a quick check for the existence of the actual ID attribute
 	// to avoid selecting by the name attribute in IE
-	if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && != m[2] )
+	// NOTE: if you have a form with a hidden field "id", IE6 will select this, even when using getAttribute instead of ""
+	if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && != m[2] && typeof != "object" )
 		oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
 	// Do a quick check for node name (where applicable) so

The patch is against SVN r1883.

Attachments (0)
Change History (3)

Changed May 13, 2007 05:20PM UTC by brandon comment:1

resolution: → fixed
status: newclosed

Fixed in SVN Rev [1896].

Changed February 02, 2010 05:22PM UTC by ttrnka comment:2

resolution: fixed
status: closedreopened

I'm still having problems updating/using a FORM element attribute 'id' in Firefox and Internet Explorer (jQuery 1.4.1 + tested on 1.3 and 1.3.2). See the code bellow:

Sample code

<form id="foo">
 <input name="id">
<script type="text/javascript">
$("#foo").attr('id', 'bar');


Firefox 3.5.7

foo-foo-null [wrong]

Internet Explorer 8.0

foo- ... crashes on line: $("#foo").attr('id', 'bar');

Google Chrome 4.0

foo-null-bar [correct]

Changed February 03, 2010 02:23AM UTC by dmethvin comment:3

resolution: → duplicate
status: reopenedclosed

I'm pretty sure this is a dup of #3113, and applies to any conflict between form attribute/properties and the names of children in the form.elements collection.