user3309148
user3309148

Reputation: 11

Correctly adding "use strict"; in this code

I need to add "use strict"; in this code . when I try to add it stops working, this is a js of a responsive navigation menu

<script>
     $(function() {
        "use strict";
            var pull        = $('#pull');
                menu        = $('nav ul');
                menuHeight  = menu.height();

            $(pull).on('click', function(e) {
                e.preventDefault();
                menu.slideToggle();
            });

            $(window).resize(function(){
                var w = $(window).width();
                if(w > 320 && menu.is(':hidden')) {
                    menu.removeAttr('style');
                }
            });
        });

    </script>

Upvotes: 1

Views: 81

Answers (1)

elclanrs
elclanrs

Reputation: 94101

You're creating global variables due to a syntax mistake. In strict mode these throw a reference error as the variable hasn't been declared:

var pull = $('#pull'), //<-- comma
    menu = $('nav ul'), //<-- comma
    menuHeight = menu.height();

Upvotes: 4

Related Questions