3

I have this command (visibleSelect is jquery variable that holds multiple select list):

var selectedOption = visibleSelect.find('option[selected=true]');

From the watch window I can see that selectedOption.length is 0, but visibleSelect.get(0)[1].selected is true.

Why selectedOption doesn't containt the selected option? What is wrong?

Naor
  • 22,523
  • 46
  • 144
  • 260

3 Answers3

4

Try

var selectedOption = visibleSelect.find('option:selected');
marramgrass
  • 1,411
  • 14
  • 17
4

use var selectedOption = visibleSelect.find('option:selected');

El Ronnoco
  • 11,453
  • 5
  • 36
  • 65
2

Description

The correct attribute value is checked="checked". But Anyway you should use the jQuery :selected selector to guarantee cross browser compatility.

visibleSelect.find('option:selected');

More Information

Community
  • 1
  • 1
dknaack
  • 58,548
  • 26
  • 144
  • 194