Bug Tracker

Modify

Ticket #2099 (closed bug: fixed)

Opened 5 years ago

Last modified 3 years ago

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:1 Changed 5 years ago by scott.gonzal

See #2188 for another test case.

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:3 Changed 5 years ago by flesler

  • Status changed from new to closed
  • Resolution set to fixed

Fixed at [5574], check #2548.

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.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.