I have the following code:
var hoverList = function(){
var width = $(window).width();
console.log(width);
if(width > 992) {
$( ".dropdown" ).mouseover(function() {
$(this).addClass('open');
});
$( ".dropdown" ).mouseleave(function() {
$(this).removeClass('open');
});
}
}
//call function on load and page resize
$(window).on('load', hoverList);
$(window).on('resize', hoverList);
this code will add an open
class to the dropdown class` only when the window width is less than 992px, since I want users to hover the menu on desktop but to click the mobile version of the navigation on mobile. And this kid of works, if I refresh the page on a size less than 992 and hover an li element the navigation does not toggle, then if I resize the window to be larger than 992px and hover an li element the navigation does toggle, but then if I go back to less than 992 and hover the li, this time the navigation toggles, I have no idea what might be causing this behavior, I''ve seen some questions similar to this one on SO but they did not help.
I would appreciate any help, thanks.
these are the questions that I foud but were not helpfull
if condition always work inside $(window).resize function
Problem with function within $(window).resize - using jQuery