Feb9
Select the last option of a drop down
Posted by: Brian Chan | Filed in: technology | Tags: programming | 04:32 pm, February 9th, 2012 Add comments
Say you have a list of drop down select options and you want to pick the last option by default when the page loads, with jquery this is how to do it.
1 2 3 | $(document).ready(function() {
$('#my_select option:last-child').attr('selected', 'selected');
}); |
Below is how you get the the value of the first, last, and the nth options.
1 2 3 | var option_first = $('#my_select option:first-child').val();
var option_last = $('#my_select option:last-child').val();
var option_nth = $('#my_select option:nth-child(0)').val(); |
Related posts:
- Disallow de-select when select-all is checked
- Stop event propagation
- dataTables editable plugin multiple select
- PHP read from a mounted drive
- PHP command line memory limit error