Modify ↓
Ticket #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: | |
| Blocking: | Blocked by: |
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
comment:2 Changed 5 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:4 Changed 3 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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

See #2188 for another test case.