Alex Rivera | Logout

jquery select option click handler

Asked 2011-04-21T20:44:08.917
81

given:

<select id="mySelect">
  <option>..</option>
  ...
</select>

Using the select id, how can I trigger a click event on one of the options? I tried attaching the event directly to the select, but this triggers an event whenever the select is clicked on (even if there are no options). Oh, and it is a multi-select (although I don't think that matter).

Edit
Report

1 Answer

93

You want the 'change' event handler, instead of 'click'.

$('#mySelect').change(function(){ 
    var value = $(this).val();
});
answered 2011-04-21T20:49:06.487

Your Answer