0

I'm new to java script, I'm using a code I found in a website to implement SHA1 hashing

 <link href="css/style.css" rel="stylesheet">
<!--newcode -->
<script src="js/sha1.js">/* SHA-256 JavaScript implementation */</script>
    <script>
        $(document).ready(function() {
            // hash listener
            $('#generate-hash').click( function() {
                var t = new Date();
                hash = Sha1.hash($('#message').val());
                $('#hash-time').html(((new Date() - t))+'ms');
                $('#hash').val(hash);
            });

            // show source code
            $.get('js/crypto/sha1.js', function(data) {
                var src = data.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') // replace &, <, >
                $('#src-code').html(src);
                prettyPrint();
            }, 'text');
        });
    </script>

the chrome console points at line 22:

$(document).ready(function() {

Uncaught ReferenceError: `$` is not defined
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
Adel Ahmed
  • 638
  • 7
  • 24

1 Answers1

1

The $ is provided by the jQuery JavaScript library. I could see in your code, you have not added it or have added it after you are calling $. You need to include jQuery.js before any jQuery based script (calling $ function) is run. Please add this before your script tag:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252