JSFiddle - React, Tailwind, and code Playground
by b9chris
HTML
<select selectedIndex=0>
<option>One</option>
<option>Two</option>
</select>
<button>Check selectedIndex</button>
<div id=output></div>
CSS
body {
font: 10pt Verdana;
}
button {
display: block;
}
JavaScript
(function($) {
$.fn.selectedOption = function() {
var sel = this[0];
return sel.options[sel.selectedIndex];
};
})(jQuery)
$('button').click(function() {
$('#output').text('selected index: ' + $('select').selectedOption().index);
});