How can I get selected option index of <SELECT> with javascript. It is easy to get value with the help of jQuery's val() method but I couldnt get the index 0, 1, 2...
I can get it by some painful ways but I believe there must be something which can do it directly.
I create my select element on fly like this :
$formInput = $('<select class="userInput">');
$.each([A,B,C,D,E], function (i, v) {
$option = $('<option value="' + v + '">' + v+ '</option>');
$formInput.append($option);
});
And all methods I tried
$formInput.prop("selectedIndex")
$formInput.get(0).selectedIndex
$formInput[0].selectedIndex
did not work.
Here is the FIDDLE