Toggle class when element is clicked, remove class when clicking anywhere outside element
$('li.has-children > a').click(function(e){
e.preventDefault();
$(e.currentTarget).parent().toggleClass('sub-nav-active');
});
$(document).on('click', function(event) {
if (!$(event.target).closest('li.has-children').length) {
$('li.has-children').removeClass('sub-nav-active');
}
});