Obtener valor(option) de elemento select al cambiar – jQuery
August 5, 2011
Leave a comment
HTML de ejemplo
<select id="mySelect">
<option value="1">option A</option>
<option value="2">option B</option>
</select>
<br/>
<span id="iSelected">Hola</span>
jQuery para conseguir el option recien seleccionado:
$('#mySelect').change(function(){
var $selectedOption = $(this).find('option:selected');
var selectedLabel = $selectedOption.text();
var selectedValue = $selectedOption.val();
$('#iSelected').text(selectedValue + ' - ' + selectedLabel);
});
Categories: jQuery, Mini-tips, Programación, Web