JQuery add or remove class based on menu item clicked : I tried this, searched in the stackoverflow.

    $(".sub>li>a").click(function(e) {

        if( $(this).hasClass("open") ) {
            $(this).removeClass("open").addClass("closed");
        } else {
            // if other menus are open remove open class and add closed
            $(this).siblings().removeClass("open").addClass("closed"); 
            $(this).removeClass("closed").addClass("open");
        }

});


but i can't. 
can you help me? 

here is my fiddle. https://jsfiddle.net/v2oLfcnf/