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
}
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.
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
}
OTHER TIPS
Since you are using the negation operator (!) your block of code is currently running when either of these scenarios are true:
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"?