You can bind some events using jQuery one function as follows:
$('select').one('click', firstClick); function firstClick(evt) { //do anything you might want to do $(evt.target).parent().one('click', secondClick); } function secondClick(evt) { //again, do you thing $(evt.target).parent().one('click', firstClick); }
The one function will execute an event handler that you specify once, and then delete it. This solution allows you to switch the handler every time you click. Just be careful if you use this one. You also need to handle the blur event to reset the first handler.
You can also use the jQuery live function to minimize the number of event handlers that you create while preserving memory. It will also avoid some of the problems that I could have anticipated with my first solution.
$('select option').live('click', selectHandler); function selectHandler(evt) {
source share