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.

[html]
<select name="mySelect" id="mySelect" class="select">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
[/html]

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

[js]
$("#mySelect option:last").attr("selected", "selected");
[/js]

Here mySelect is the ID of our element.

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

Kindest Regards
Sibeesh Venu

Leave a Reply

Your email address will not be published. Required fields are marked *

Serverless 360