Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#9685 closed bug (duplicate)

attr('selectedIndex') Not Working with FF in 1.6.2 RC1

Reported by: sradoff@… Owned by:
Priority: low Milestone: 1.next
Component: attributes Version: 1.6.1
Keywords: Cc:
Blocked by: Blocking:

Description

$(this).attr('selectedIndex') not working in FF where $(this) is a change event from a select control. Returns undefined. Works with IE6. Works OK with 1.5.1.

Change History (5)

comment:1 Changed 12 years ago by ajpiano

Component: unfiledattributes
Priority: undecidedlow
Resolution: duplicate
Status: newclosed

selectedIndex is not an attribute.

comment:2 Changed 12 years ago by ajpiano

Duplicate of #9088.

comment:3 Changed 12 years ago by sradoff@…

Why is the selectedIndex not an attribute? When I examine the javascript definitions it shows selectedIndex is a property of a select object. How come $(this).attr('selectedIndex') works in 1.5 but not in 1.6.2 RC1? If selectedIndex is not an attribute as claimed then how would one retrieve the selected index of a select control?

comment:4 Changed 12 years ago by dmethvin

Why is the selectedIndex not an attribute?

Because it is a *property*.

When I examine the javascript definitions it shows selectedIndex is a property of a select object.

Yes, you are correct, it is a property.

How come $(this).attr('selectedIndex') works in 1.5 but not in 1.6.2 RC1?

We fixed a bug.

If selectedIndex is not an attribute as claimed then how would one retrieve the selected index of a select control?

Use $(this).prop("selectedIndex") or (even better) this.selectedIndex which is probably more than 100 times faster to execute.

comment:5 Changed 12 years ago by Timmy Willison

@sradoff Sorry for the confusion. selectedIndex is a property and should never have been retrieved with attr, even though it admittedly did retrieve it. Since 1.6, jQuery has a function for retrieving native properties such as selectedIndex(http://api.jquery.com/prop), but in the past (and this continues to be true) selectedIndex could simply be retrieved with raw javascript:

this.selectedIndex

DaveMethvin ganked me, but I'll post anyway.

Note: See TracTickets for help on using tickets.