Bug Tracker

Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#2099 closed bug (fixed)

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'.

Change History (4)

comment:1 Changed 15 years ago by scott.gonzal

See #2188 for another test case.

comment:2 Changed 15 years ago by robyn

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 :)

comment:3 Changed 15 years ago by flesler

Resolution: fixed
Status: newclosed

Fixed at [5574], check #2548.

comment:4 Changed 13 years ago by anonymous

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.

Note: See TracTickets for help on using tickets.