Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery select option click handler

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).

like image 595
john Avatar asked Apr 21 '11 20:04

john


1 Answers

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

$('#mySelect').change(function(){      var value = $(this).val(); }); 
like image 190
Matt Avatar answered Sep 21 '22 08:09

Matt