var original_role = $('option:selected', '#user_role').val();
$('#role_cancel').click(function() {
//console.log(original_role);
$('option:selected', '#user_role').removeAttr('selected'); //deselect current option
$('#user_role').find('option[value="' + original_role + '"]').attr('selected'); //select original value
});
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#banner-message {
background: #fff;
border-radius: 4px;
padding: 20px;
font-size: 25px;
text-align: center;
transition: all 0.2s;
margin: 0 auto;
width: 300px;
}
button {
background: #0084ff;
border: none;
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
color: #fff;
}
#banner-message.alt {
background: #0084ff;
color: #fff;
margin-top: 40px;
width: 200px;
}
#banner-message.alt button {
background: #fff;
color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="banner-message">
<div class="col-md-9">
<select name="user_role" class="form-control" id="user_role">
<option value="0">Ninguno</option>
<option value="1">Admin</option>
<option value="24">Secretario general</option>
<option value="25">SecretarioExcursiones</option>
<option value="26">Tesorería</option>
<option value="27">Almacen</option>
<option value="28">Coordinador</option>
<option value="30">Reta</option>
<option value="31">Invitado</option>
<option value="32" selected="">Prospecto</option>
<option value="33">Presidente</option>
<option value="34">Eventos especiales</option>
<option value="36">Guía</option>
<option value="37">Soci@</option>
<option value="38">Inivtado</option>
</select>
</div>
<button id="role_cancel">
RESET
</button>
</div>
When pressing RESET, the select should
- Remove selected attr/prop from whatever option in the dropdown was selected
- Select the originally selected value from the dropdown (make the change visually and in DOM)
So far is doing none of this.