I have a <select>
element on my form with the multiple attribute set to "true". After the element gets populated, how can I select the last item in the list using jquery? I want the item to be selected the same way you select it with a mouseclick:
You can try
var myVal = $('.someclass option:last').val();
$('.someclass').val(myVal);
where someclass is the select class or it's wrapper element class.
fiddle link
You can do this by index value as well:
var num = $('select option').length;
$('select').prop('selectedIndex', num-1); // For choosing last item in list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With