The name of the event when selecting an option within the selected

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

Example:

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

When I press Option 1 , what event is happening? Only change (on the select screen itself and that's it) or something else?

Thanks.

+7
source share
4 answers

By default, in most browsers, the change event occurs when select and click events for option change .

 $('select').on('change', function(event) { console.log(event.type); // event.type is to get event name }); 
+8
source

"change" to SELECT and 'click' to OPTION. In addition, in Opera, an β€œinput” can also work in SELECT if you add a listener using addEventListener (), for example.

+2
source

event.type returns the nature of the event. See Demo

 $('select').bind('change', function(event) { alert("Event :"+ event.type); }); 

You can use .on / .bind for an element.

+1
source

You can put it in the onclick event of the option you are interested in:

 <select id="MySelect"> <option id="optionA" onclick="alert('You clicked A')">a</option> <option id="optionB">b</option> </select> 
0
source

All Articles