1
$('div').mouseenter(function() {
    $(this).slideUp(150);
});

$('div').mouseenter(function() {
    $(this).slideDown(150);
});

How can I combine this into something smaller?
Don't know enough jQuery / JS for this yet.

George Kagan
  • 5,913
  • 8
  • 46
  • 50
Alexander Graham
  • 407
  • 1
  • 3
  • 10
  • Possible duplicate of [Combining jquery functions - on() hover/mouseenter/mouseleave](http://stackoverflow.com/questions/9812062/combining-jquery-functions-on-hover-mouseenter-mouseleave) – rnevius Nov 04 '16 at 19:41

2 Answers2

3

You can use .on() to bind a function to multiple events:

$('div').on('event1 event2', function(e) {
 $(this).slideToggle(150);
});
mukesh kudi
  • 719
  • 6
  • 20
2
$('div').on('mouseenter mouseleave', function() { 
   ...
})

Another benefit of using .on() is event delegation, meaning any future divs will also trigger the events, instead of manually binding the event on them.

George Kagan
  • 5,913
  • 8
  • 46
  • 50