Make Last Option As Selected In Select,Drop Down,Combo Box

In this post we will see how we can make the selected property to the last option of a select or drop down or combo box. We will use a Jquery selector for making the last option as selected.

Consider I have a following select element.

  1. <select name="mySelect" id="mySelect" class="select">  
  2.    <option>1</option>  
  3.    <option>2</option>  
  4.    <option>3</option>  
  5.    <option>4</option>  
  6.    <option>5</option>  
  7. </select>  

Now by default we need that last option as selected right? To do that we can use the following script.

  1. $("#mySelect option:last").attr("selected""selected");  

Here mySelect is the ID of our element.

Please see my other posts related to JQuery here: JQuery Posts

Kindest Regards
Sibeesh Venu