This question is similar to at least one other question, but the resolution didn't help me. I have some code that worked great in jQuery 1.4, but works no longer. I have two buttons that (used to) allow the user to navigate thru a select list. Here's the working version:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<button onclick="setOption(-1)">←</button>
<button onclick="setOption(1)">→</button>
<select name="select1" id="select1">
<option value=""></option>
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
</body>
</html>
JS:
function setOption(num) {
var current = $( "#select1" ).attr( "selectedIndex" )
var next = current + num;
$('#select1 option:eq('+next+')').attr('selected', 'selected');
}
What do I need to update to make it work in, say, jQuery 1.11.0?
Thanks in advance!