Reputation: 41473
I have a select box with the following data
<select>
<option>Bill</option>
<option>Ted</option>
<option>Bogus</option>
</select>
When i select "Bogus" i want to return 2 back to a function, because this is the third item.
Any idea how to do this with jQuery? Something like
jQuery("#colour").change(function(){
alert( $(this).index );
});
doesn't work.
Thanks
Upvotes: 1
Views: 75
Reputation: 22535
You can also modify your jquery to use the index method
$('option:selected', this).index()
Upvotes: 0
Reputation: 221106
After all this jquery business, we forget how it was done before... ;-)
It's
this.selectedIndex
Upvotes: 5