3

I have a jquery script. Tried it in Chrome and IE, all good, no errors. Tried it on firefox, "ReferenceError: jQuery is not defined" .

(function($) {
    $(document).ready(function() {
        $('#cssmenu > ul > li > a').click(function() {
            $('#cssmenu li').removeClass('active');
            $(this).closest('li').addClass('active');
            var checkElement = $(this).next();
            if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                $(this).closest('li').removeClass('active');
                checkElement.slideUp('normal');
            }
            if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                $('#cssmenu ul ul:visible').slideUp('normal');
                checkElement.slideDown('normal');
            }
            if ($(this).closest('li').find('ul').children().length == 0) {
                return true;
            } else {
                return false;
            }
        });
    });
})(jQuery);

I read some similar problems but i'm not that good with jquery.

Satpal
  • 132,252
  • 13
  • 159
  • 168
georgeB
  • 164
  • 1
  • 9

1 Answers1

3

Include jQuery library in your code:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script>
(function($) {
    $(document).ready(function() {
    $('#cssmenu > ul > li > a').click(function() {
        $('#cssmenu li').removeClass('active');
        $(this).closest('li').addClass('active');
        var checkElement = $(this).next();
        if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
            $(this).closest('li').removeClass('active');
            checkElement.slideUp('normal');
        }
        if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
            $('#cssmenu ul ul:visible').slideUp('normal');
            checkElement.slideDown('normal');
        }
        if ($(this).closest('li').find('ul').children().length == 0) {
            return true;
        } else {
            return false;
        }
    });
});
})(jQuery);

</script>
captainsac
  • 2,484
  • 3
  • 27
  • 48
  • i had already included : , but the odd thing is that your way works now. I replaced my jquery with your jquery. What could be the answer ? Thank you ! – georgeB May 13 '15 at 10:55
  • i had it. when i paste-it inside here it removed it. – georgeB May 13 '15 at 11:09
  • I observed something : i can use my link or yours as long as i don't use async atribute. I have 4 – georgeB May 13 '15 at 11:22