Is there a way to combine the following two instructions into more efficient code?
$('.sandwiches').mouseleave(function () {
$('.sandwiches').hide();
});
$('.food').mouseleave(function () {
$('.sandwiches').hide();
});
By combining the selectors:
$('.sandwiches,.food').mouseleave...
$('.sandwiches,.food').on('mouseleave',function...); which I believe creates just one..mouseleave is identical to .on('mouseleave') in that they both bind the handler to every element in the matched selection. In the case of delegated events (i.e. $('.foo').on('mouseleave', '.bar', fn)) handlers are bound to every element in the initial matched selection (i.e. every .foo element would have a handler, but it's likely that the .bar elements are far more numerous).$('.sandwiches, .food').mouseleave(function () {
$('.sandwiches').hide();
});