How to select the first option in a combo box?

Simply in jQuery (a Javascript framework – Write less, do more):

?View Code JAVASCRIPT
1
$("#div_id option:first).attr("selected","selected"); 

Example: 

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
$('#myCombo').load(
                              'my_combo.php?foo=bar',
                               function() {
                                     $('#myCombo option:first).attr("selected","selected");
                               }
                      );
html:
<select id="myCombo"></select>
[Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
This entry was posted in jQuery. Bookmark the permalink.

2 Responses to How to select the first option in a combo box?

  1. Sao ko để chễ độ Read more cho dễ đọc vậy bạn/

  2. :) uhm, cũng chỉ có vài bài là dài thôi mà bạn (toàn đi copy từ nguồn khác post vào :D )

Leave a Reply

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

*

CAPTCHA image
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>