-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Description
I've just been looking into an issue whereby if you have a select element with the multiple option set and no options selected $().val() will return null rather than an empty array. If one more more items are selected, then it returns an array. I would have expected that an empty array would have been returned in this case.
This fiddle shows the issue. IT appears all the way back to jQuery 1.2 where multiple value support was added.
The reason an empty array is not returned is the check for elem.selectedIndex being < 0 here. While I understand that for a single select, I don't while get why that would be done for a multi-select.
Removing || index < 0 would allow the empty array to be returned.
Having said that, I'm not really expecting this change to be made as I guess a number of sites will depend upon this behaviour. I'm more wondering if someone might be willing to say why it is done this way? I've searched this issue tracker and the bugs.jquery.com site, but couldn't find any mention of it.