Bug Tracker

Modify

Ticket #9685 (closed bug: duplicate)

Opened 2 years ago

Last modified 14 months ago

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:
Blocking: Blocked by:

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

comment:1 Changed 2 years ago by ajpiano

  • Priority changed from undecided to low
  • Resolution set to duplicate
  • Status changed from new to closed
  • Component changed from unfiled to attributes

selectedIndex is not an attribute.

comment:2 Changed 2 years ago by ajpiano

Duplicate of #9088.

comment:3 Changed 2 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 23 months 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 23 months ago by timmywil

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

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.