You can check if the closest element has a ulparent element nav.sidebar:
$('.expandingNav').on('click', function (e) {
if ($(e.target).closest('ul').parent('nav.sidebar').length) {
}
});
Updated example
$('.expandingNav').on('click', function (e) {
if ($(e.target).closest('ul').parent('nav.sidebar').length) {
if ($(this).hasClass('expanded')) {
$(this).children('.hidden').slideUp();
$(this).removeClass('expanded');
} else {
$(this).children('.hidden').slideDown();
$(this).addClass('expanded');
}
}
});
Alternatively, you can also check if the parent is the following sibling ul:
$('.expandingNav').on('click', function (e) {
if ($(e.target).parent().next('ul').length) {
}
});
Updated example
$('.expandingNav').on('click', function (e) {
if ($(e.target).parent().next('ul').length) {
if ($(this).hasClass('expanded')) {
$(this).children('.hidden').slideUp();
$(this).removeClass('expanded');
} else {
$(this).children('.hidden').slideDown();
$(this).addClass('expanded');
}
}
});