Using jQuery to hide a sub-menu on mouseleave, everything works fine, but when I try to use setTimeout the function doesn't work.
This is my code without setTimeout
$( "li.menu-item" ).hover(function() {  // mouse enter
  $( this ).find( ".sub-menu" ).show(); // display child
}, function(){ // mouse leave
  $( this ).find( ".sub-menu" ).hide(); 
});
And with setTimeout:
$( "li.menu-item" ).hover(function() {  // mouse enter
  $( this ).find( ".sub-menu" ).show(); // display child
}, function(){ // mouse leave
  setTimeout(function () {
    $( this ).find( ".sub-menu" ).hide();
  }, 2000);            
});
The setTimeout function is working, if I insert an alert inside, the execution is with 2 seconds delay.
Thank You.
 
     
     
    