-1

Sorry im new to jquery I usually use php/html. Can you tell why my code wont console log the VAR values. I am building an array from my vars when looping through them. I get the error Uncaught ReferenceError: $ is not defined.

Fiddle

    var string1 = "tes£$%t";
    var string2 = "test";
    var string3 = "test";
    var string4 = "test";

    var check_fields = [string1, string2, string3, string4];

    $.each(check_fields, function(index, value) {

        if (value.replace(/^[a-z\d\-_\s]+$/i, "") != string) {
        console.log(value);

        }

    });
JIMMY THE CODE
  • 161
  • 1
  • 7

3 Answers3

2

Your code is fine but jquery file is missing here. Fiddle link:- In the left side under the external resource just put the jquery cdn path and click on run then check.

https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js

This will resolve your problem.

Deepak Dholiyan
  • 1,774
  • 1
  • 20
  • 35
1

include the jquery header file in the head your html code

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

</head>
Asad
  • 3,070
  • 7
  • 23
  • 61
0

Your html file is missing the external jQuery library.
Try adding this to the start of your html file (preferably in the head, of in the case of JSFiddle just paste it into the HTML box):

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

Let me know if this works

JakobRuf
  • 59
  • 1
  • 4