I have a 'select' drop-down with a list of players' names, which by default has the first item--also an empty item, selected. I would like to do a simple test on whether this item is selected when the user clicks a button below.
I came across two possible solutions:
1)
if( $("#players option:selected").is(":eq(0)") )
{
alert("Please select a player!");
}
and
2)
if( $("#players option:eq(0)").is(":selected") )
{
alert("Please select a player!");
}
Solution #2 works perfectly, but #1 always returns true. Does anyone know of a technical reason or limitation on why this is?
Thanks for your replies!