I need to remove a certain css class from .nav
, so that it comes up properly. Right now its behaviour is unexpected based on different screen sizes.
Fiddle example
You will notice that the drop-down sub-menus don't show up properly. I want the dropdown to show on right side of dropdown, when it has enough space on the right, and on the left side of dropdown, when it has less space based on the <div class="main-wrapper">
width, which is 1000px wide.
I tried to fix it with following code but it is not working properly:
$(document).ready(function(){
$(".nav").on("mouseenter", " > li", function(){
/*if dropdown is likely to go out of parent nav then right align it :) */
if (($(this).offset().left) + 200 > $('.menu-wrapper').width()) {
$(this).find(".dropdown").addClass("dropdown-last");
}
if($(this).hasClass("has-panel")){
// $(this).find(".dropdown").removeClass("dropdown-last");
//alert('has class');
}
else
{
//alert('has no class');
}
});
/* if dropdnw*/
$(".dropdown").each(function(){
var $this = $(this);
if($this.find(".dd-panel").length > 0){
$this.addClass('has-panel');
}
if($this.find(".dd-panel").length = 1){
$(".dropdown").css( "min-height", "80px" );
}
});
});
On debug, it shows the following as a div class dropdown has-panel dropdown-last
if it div with has class has-panel
and one which doesnt have mega menu for it show class as dropdown dropdown-last
. I was trying to check using jQuery, to see if the element has the class or not. If it has the class has-panel
, then do nothing and if it doesn't have the class has-panel
, then I need to remove the class dropdown-last
from the same element which is not working with following code:
if($(this).hasClass("has-panel")){
// $(this).find(".dropdown").removeClass("dropdown-last");
alert('has class');
}
else
{
//alert('has no class');
}