Archive

Archive for the ‘jQuery’ Category

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);
});

JsFiddle con el ejemplo

Scroll to the top of the page with jQuery

March 30, 2011 Leave a comment


$('html').scrollTop(0);

Si quieres hacerlo que se vea como animado puedes hacer:

$('html').animate({scrollTop:0}, 'slow');

Follow

Get every new post delivered to your Inbox.

Join 175 other followers