<!DOCTYPE html> <html> <head> <style> * { font-size: 125%; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#contriner').on('click','#btn',function(e){ var last=$('#swap option:last').val(); if(last != $('#swap option:selected').val()) { $('#swap option:selected').next().prop('selected', 'selected'); }else{ $("#swap option:first").prop('selected','selected'); } }); }); </script> </head> <body> <div id="contriner"> <select id='swap' name="swap"> <option value="AAA">AAA</option><br/> <option value="BBB">BBB</option><br/> <option value="CCC">CCC</option><br/> </select> <br><br> <input type="button" id ='btn' value="Swap Text"> </div><br> </body> </html>
<div id="contriner"> <select id='swap' name="swap"> <option value="AAA">AAA</option><br/> <option value="BBB">BBB</option><br/> <option value="CCC">CCC</option><br/> </select> <br><br> <input type="button" id ='btn' value="Swap Text"> </div><br>
$(document).ready(function(){ $('#contriner').on('click','#btn',function(e){ var last=$('#swap option:last').val(); if(last != $('#swap option:selected').val()) { $('#swap option:selected').next().prop('selected', 'selected'); }else{ $("#swap option:first").prop('selected','selected'); } }); });