You cannot use the ||
(or) operator within hasClass
. Try this:
if ($('#menu-item-49').hasClass('current-menu-item') ||
$('#menu-item-49').hasClass('current-menu-parent')) {
$('ul.sub-menu ').css('display', 'block');
}
Or you can do this if that's too verbose:
var $menuItem = $('#menu-item-49');
if ($menuItem.hasClass('current-menu-item') ||
$menuItem.hasClass('current-menu-parent')) {
$('ul.sub-menu ').css('display', 'block');
}
Or even better:
var $menuItem = $('#menu-item-49');
if ($menuItem.is('.current-menu-item, .current-menu-parent')) {
$('ul.sub-menu ').css('display', 'block');
}