Hi nauna,
You can use JavaScript setTimeout and clearTimeout function.
Refer below JavaScript code.
<form id="form1" runat="server">
<div>
<ul id="menu"></ul>
</div>
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/blitzer/jquery-ui.css" />
<script type="text/javascript">
$(function () {
$('ul').menu();
$.ajax({
url: "Handler.ashx",
method: 'GET',
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (data) {
$.each(data, function () {
var li = $('<li value="' + this.Id + '">' + this.MenuText + '</li>');
if (!this.Active) {
li.addClass('ui-state-disabled');
}
li.appendTo($('#menu'));
});
}
});
var timer;
$('body').on('mouseenter', 'ul li', function () {
var menu = $(this);
var id = $(this).attr('value');
timer = setTimeout(function () {
$.ajax({
url: "Handler.ashx?ParentId=" + id,
method: 'GET',
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (data) {
var ul = $('<ul></ul>').empty();
$.each(data, function () {
var li = $('<li value="' + this.Id + '">' + this.MenuText + '</li>');
if (!this.Active) {
li.addClass('ui-state-disabled');
}
li.appendTo($(ul));
});
$(ul).appendTo($(menu));
}
});
}, 500);
});
$('body').on('mouseleave', 'ul li', function () {
$(this).find('ul').remove();
clearTimeout(timer);
});
});
</script>