Tuesday, April 29, 2014

How to reset select tag with jQuery

http://jsfiddle.net/TmJCE/10/


$('#name2').change(function(){
    $('#name').prop('selectedIndex',0);
});


$('#name').change(function(){
    $('#name2').prop('selectedIndex',0);
});
and html is ->
<select id="name" >
    <option value="">select all</option>
    <option value="1">Text 1</option>
    <option value="2">Text 2</option>
    <option value="3">Text 3</option>
</select>


<select id="name2" >
    <option value="">select all</option>
    <option value="1">Text 1</option>
    <option value="2">Text 2</option>
    <option value="3">Text 3</option>
</select>


the main code is 

$('#to').prop('selectedIndex',0);

where #to is id of my select tag . put it anywhere on an event listener

0 comments:

Post a Comment