jqueryUI seletmenu selctedindex

jquery ui selectmenu find value by index and set index

by ltdeta

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/redmond/jquery-ui.css">
<select class="select" id="one">
    <option value="1a">A</option>
    <option value="2b">A</option>
    <option value="3c">A</option>
    <option selected value="4d">B</option>
</select>

JavaScript

$(".select").selectmenu();

console.log('A:' + $(".select")[0].selectedIndex + ' / ' + $(".select").val());
$(".select").prop('selectedIndex', 1);
console.log('B:' + $(".select")[0].selectedIndex + ' / ' + $(".select").val());