kamilus
kamilus

Reputation: 29

on click the class has added but on clicking another the same class which was added is not removed

on clicking nav-icon class "show-menu" has added to the body,but on clicking class nav-close the class show-menu has not removed from the body


     $(document).ready(function(){
        $('.nav-icon').click(function(e) {
            e.stopPropagation();
            if(!$('body').hasClass("show-menu") ){
                $('body').addClass("show-menu");
            };
        });
        $('.nav-close').click(function(){
            if( $('body').hasClass("show-menu") ){
                $('body').removeClass("show-menu");
            };
        });
     });

Upvotes: 1

Views: 83

Answers (1)

John Louie Dela Cruz
John Louie Dela Cruz

Reputation: 669

Try putting your functions outside $(document).ready(function(){}); only put functions inside $(document).ready when you want you execute the functions when the page or DOM elements are loaded i don't think you need to place your code inside it.

Upvotes: 0

Related Questions