#9685 closed bug (duplicate)
attr('selectedIndex') Not Working with FF in 1.6.2 RC1
Reported by: | 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
Component: | unfiled → attributes |
---|---|
Priority: | undecided → low |
Resolution: | → duplicate |
Status: | new → closed |
comment:3 Changed 12 years ago by
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
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
@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.
selectedIndex is not an attribute.