Question

$(document).ready(function(){
if (!$('body').hasClass('home') || !$('ul#main-menu li.wwd').hasClass('active')){
$("ul#sub-menu").css('display','none');
$(".main-content").css('margin-top','13px');
$("ul#sub-menu").mouseover(function() {
        $("ul#sub-menu").show();
        $(".main-content").css('margin-top','62px');

}).mouseout(function() {
        $("ul#sub-menu").hide();
        $(".main-content").css('margin-top','13px');
});
$("li.wwd").mouseover(function() {
        $("ul#sub-menu").show();
        $(".main-content").css('margin-top','62px');
}).mouseout(function() {
        $("ul#sub-menu").hide();
        $(".main-content").css('margin-top','13px');
});
}
if ($('ul#main-menu li.wwd').is('.active')){
        $(".main-content").css('margin-top','62px');

}
})

I need to run this jQuery on all pages besides the home page(that works fine) but also not on pages where li.wwd has class active. I thought this would work with an OR operation but it does not. Thanks for any help in advance.

Était-ce utile?

La solution

To evaluate the !(not) condition for both places you need to use && instead of ||, just like

if (!$('body').hasClass('home') && !$('ul#main-menu li.wwd').hasClass('active'))
{
    // code goes here
}

Autres conseils

Since you are using the negation operator (!) your block of code is currently running when either of these scenarios are true:

  1. body does NOT have the class "home" OR
  2. ul#main-menu li.wwd does NOT have the class "active"

So I suspect your home page code appears to be working fine because on that page, the ul#main-menu li.wwd might not have the class "active"?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top