Adding a delay/timeout to dropdown menu

Adding a delay/timeout to dropdown menu

Hi everyone, I'm new to this forum!

The code below is working fine for me, however I would like to add a delay / timeout to it..
Everytime I move my mouse off the element it jumps away really fast..
  1. <script type="text/javascript">
  2. // Executes the function when DOM will be loaded fully
  3. $(document).ready(function () {
  4. // hover property will help us set the events for mouse enter and mouse leave
  5. $('.menu li').hover(
  6. // When mouse enters the element
  7. function () {
  8. //Fade in the navigation submenu
  9. $('ul', this).fadeIn(); // fadeIn will show the sub cat menu
  10. }, 
  11. // When mouse leaves the element
  12. function () {
  13. //Fade out the navigation submenu
  14. $('ul', this).fadeOut(); // fadeOut will hide the sub cat menu
  15. }
  16. );
  17. });
  18. </script>