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.
- <select name="mySelect" id="mySelect" class="select">
- <option>1</option>
- <option>2</option>
- <option>3</option>
- <option>4</option>
- <option>5</option>
- </select>
Now by default we need that last option as selected right? To do that we can use the following script.
- $("#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