Skip to main content

Bug Tracker

Side navigation

#2099 closed bug (fixed)

Opened December 28, 2007 08:43PM UTC

Closed May 13, 2008 12:40AM UTC

Last modified November 02, 2010 04:42PM UTC

IE: $('#someform').attr('id') returns sub element instead of attribute

Reported by: streawkceur Owned by:
Priority: major Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: attr ie form Cc:
Blocked by: Blocking:
Description

HTML:

<form id="someform" name="someform">
    <input name="id" value="23" />
</form>

JS:

$('#someform').attr('id')

Gives '[object]' in IE. This is actually the input element.

In FF the correct value 'someform' is alerted.

"Fix":

if (jQuery.browser.msie) {
    alert( $('#someform').attr('attributes')['id'].value );
} else {
    alert( $('#someform').attr('id') );
}

This error may occur on several other attributes.

Also, it works when there is no sub-element with the name 'id'.

Attachments (0)
Change History (4)

Changed January 18, 2008 03:49PM UTC by scott.gonzal comment:1

See #2188 for another test case.

Changed April 11, 2008 04:48PM UTC by robyn comment:2

change line 1067 in jquery-uncompressed.js (version 1.2.3)

from

else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName( elem, "form" ) && (name == "action" || name == "method" ) )

to

else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName( elem, "form" ) && (name == "action" || name == "method" || name == "id") )

this will solve the problem :)

Changed May 13, 2008 12:40AM UTC by flesler comment:3

resolution: → fixed
status: newclosed

Fixed at [5574], check #2548.

Changed November 02, 2010 04:42PM UTC by anonymous comment:4

I think there's a very similar bug:

http://jsfiddle.net/ack7U/2/

This linked script gives a result in Chrome, but in IE it gives an error message.