I have a html page with a select element like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<select id="ExSelect">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select>
<br>
<br>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<button onclick="ToTheNext()" id="btnext">Next</button>
</body>
</html>
And I'm using this simple function on the button OnClick to change the selected item to the next option item of the dropdown:
function ToTheNext()
{
$('#ExSelect option:selected').next().attr('selected', 'selected');
}
My question is: How can i change the selected item to the previous option of this tag using Vanilla JavaScript or jQuery?
Jsbin Example: https://jsbin.com/nuyeduf/edit?html,js,output