Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery select events

Tags:

jquery

i am working with a select. I want to trigger and event when the user select a value.

I am using the event "change", the problem is that if a user open the select but choose the same option that is selected, the triggers doesn't fire.

Is there a way to capture the event when a user select an option independently if the option is the same than is the one that was selected?

thanks.

like image 345
Patxi1980 Avatar asked Mar 12 '10 15:03

Patxi1980


2 Answers

You can catch both the change and click events using the bind method. This should allow you to catch most keyboard and mouse interactions

$('selector').bind('click change',function() {})
like image 172
Neil Aitken Avatar answered Oct 31 '22 15:10

Neil Aitken


I'm not sure whether it's a cross-browser solution but something like this:

$("#mySelect option").click(function() {
    // do sth
});

Works well in Opera/Firefox.

like image 45
Crozin Avatar answered Oct 31 '22 14:10

Crozin