Hello, I have the following code, which is part of a function, called to load the first child's href value to its parent menu when being on the homepage of a website. However, although this part is working fine, every time I return to my homepage, since the parent menu is still in active mode, it redirects me again on the page, while I want to modify it so that when I return on the homepage, no menu is selected at that time. Currently the redirection is being done in the window.location part when one clicks on the parent menu, with on the homepage the child menus being hidden, and shown only on the internal pages.
How can I stop this redirection from taking place when going back to the hompage with this piece of code??

Code:
$.ajax({
		type: "POST",
		url: "./controllers/pages/menus-level-ajax.php",
		data: "menuId=" + menuId + "&menuLevel=" + menuLevel,
		async: false,
		success: function(html) {			
			var level = menuLevel + 1;
					
			
			if (menuLevel == 1 && IS_HOMEPAGE == 1) {				
				$('#menu-level-' + level).html(html);
								
				$('#menu-level-' + level).css('visibility', 'hidden');				
									
				var hrefLink = $('#menu-level-2').find('a:first').attr('href');						
				$('#menu-level-2').css('display', 'none');
				window.location = hrefLink;			
																		
			}else {
				$('#menu-level-' + level).html(html);								
			}