-2
  $(document).ready(function(){

     var hamburger = $(".hamburger");
     var line = $(".line");
     var menuOpen;

     function openMenu() //function used to open menu
     {
       menu.css("left", "0px");
       line.css("background", "#FFF");
       menuOpen = true;
      }

       function closeMenu() //closing the menu
      {
       menu.css("left", "-320px");
       line.css("background", "#BCAD90");
       menuOpen = false;
       }

       function toggleMenu(){ // toggle between opening ang closing menu
        if (menuOpen){
         closeMenu();
       } 
       else 
       {
        openMenu();
       }
       }

       hamburger.on({      //hamburger menu
        mouseenter: function(){
       openMenu();
       }
      });

      menu.on({  
       mouseleave: function(){
      closeMenu();
      }

      });

      hamburger.on({
       click: function(){
      toggleMenu();
      }
      })


     });

Above is the code snippet for both Javascript and HTML files, but after compiling the above code it shows the error message in the browser as "Uncaught Reference Error: $ is not defined".kindly resolve this error and suggest the necessary solution.

Arpit Solanki
  • 9,567
  • 3
  • 41
  • 57
VIVEK S
  • 1
  • 2

2 Answers2

0

Add jQuery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
maelswarm
  • 1,163
  • 4
  • 18
  • 37
0

The browser is unable to load JQuery library. It seems like you have missed the script for loading it.

Embed the following in your index.html

<script
 src="http://code.jquery.com/jquery-3.2.1.min.js"
 integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
 crossorigin="anonymous"></script>

Thanks

Sudhanshu Gupta
  • 331
  • 1
  • 6
  • But I'm getting the same error here is the code snippet for HTML. ♪ EuroMusic ® – VIVEK S Aug 06 '17 at 19:09
  • Welcome to EuroMusic

    Listen to latest track hits of 2017
    – VIVEK S Aug 06 '17 at 19:11
  • and stylesheet detailsbody { background: #DDD8D5; color: #91966E; margin: 0; padding: 0; height: 100%; width: 100; font-family: 'Helvetica Neue'; font-weight: 100; font-size: 2rem; } h1,h5 { font-weight: 100; } – VIVEK S Aug 06 '17 at 19:12
  • section { background: #E4E4E6; padding: 6rem 3rem; margin: 0; } .hamburger { position: absolute; margin: 6px; z-index:2; cursor: pointer; } .line { width: 50px; height: 6px; background: #BCAD90; margin-bottom: 5px; } .menu { width: 320px; height: 100%; background: #BCAD90; position: fixed; top: 0; left: -320px; transition: left .1s; } .menu-item:first-child { margin-top: 180px; } .menu-open { left: 0; } .menu-item { color: #fff; width: 100px; padding: 1rem 3rem; box-sizing: border-box; } – VIVEK S Aug 06 '17 at 19:14
  • If you see in your code snippet The code to load your file i.e. Since the browser interprets the code line by line, it first parses your file and then loads jQuery. Solution: Move the code to load jquery before the code where your file is being loaded. – Sudhanshu Gupta Aug 06 '17 at 19:18