Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event name when select an option inside a select

I know the event name when we change something in a select is change (html: onchange), but I would like to know what is the event name when I select (click) a specific option.

Example :

<select>
    <option>Option 1</option>
</select>

When I click on Option 1, what event happen ? Only change (on the select itself and all option) or something else ?

Thanks.

like image 393
David Bélanger Avatar asked Jun 05 '12 16:06

David Bélanger


2 Answers

By default, in most browser happen change event when you change select and click event for option.

$('select').on('change', function(event) {
  console.log(event.type);   // event.type is to get event name
});
like image 159
thecodeparadox Avatar answered Nov 02 '22 22:11

thecodeparadox


'change' on the SELECT and 'click' on the OPTION. Also, in Opera, 'input' might fire on the SELECT too if you add the listener with addEventListener() for example.

like image 34
Shadow2531 Avatar answered Nov 02 '22 22:11

Shadow2531