ReferenceError: $ is not defined

I have this error message ReferenceError: $ is not defined
This is my header.

<link href="css/global-style.css" rel="stylesheet" type="text/css" media="screen">
<link rel="stylesheet" type="text/css" media="screen" href="css/datepicker3.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="assets/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-datepicker.js"></script>

Following is my JavaScript code

<script type="text/javascript">
$('#sandbox-container .input-daterange').datepicker({
    startDate: "today",
    calendarWeeks: true,
    todayHighlight: true

Following is the HTML

<div class="col-md-12" id="sandbox-container">
    <label>Project Duration</label>
    <div class="input-daterange input-group" id="datepicker">
            <input type="text" class="input-md form-control" name="start" />
            <span class="input-group-addon">to</span>
            <input type="text" class="input-md form-control" name="end" />

I want to show datepicker on the input tag.
I am using Bootstrap V3.1.
i am using this datepicker



Add jQuery library before your script which uses $ or jQuery so that $ can be identified in scripts.

<script src=""></script>

Use Google CDN for fast loading:

<script type="text/javascript" src="//"></script>

Add this script inside head tag:

<script type="text/javascript" src="//"></script>

It's one of the common mistake everybody make while working with jQuery, Basically $ is an alias of jQuery() so when you try to call/access it before declaring the function will endup throwing this error.

Reasons might be

1) Path to jQuery library you included is not correct.

2) Added library after the script were you see that error

To solve this

Load the jquery library beginning of all your javascript files/scripts.

<script src=""></script>

jQuery is a JavaScript library, The purpose of jQuery is to make code much easier to use JavaScript.

The jQuery syntax is tailor-made for selecting, A $ sign to define/access jQuery.

Its in declaration sequence must be on top then any other script included which uses jQuery

Correct position to jQuery declaration :

    console.log('hi from jQuery!');
<script src=""></script>
<script src=""></script>
<script src=""></script>

Above example will work perfectly because jQuery library is initialized before any other library which is using jQuery functions, including $

But if you apply it somewhere else, jQuery functions will not initialize in browser DOM and it will not able to identify any code related to jQuery, and its code starts with $ sign, so you will receive $ is not a function error.

Incorrect position for jQuery declaration:

    console.log('hi from jQuery!');
<script src=""></script>
<script src=""></script>
<script src=""></script>

Above code will not work because, jQuery is not declared on the top of any library which uses jQuery ready function.


Though my response is late, but it can still help.

lf you are using Spring Tool Suite and you still think that the JQuery file reference path is correct, then refresh your project whenever you modify the JQuery file.

You refresh by right-clicking on the project name -> refresh.

That's what solved mine.


Change your code to:


<LINK rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src=""></script>
<script src="//"></script>
<script src=""></script>

<p>Location: <input type="text" id="searchTextField" size="50"  placeholder="Where do you want to go ?"/></p>

<div id="results"></div>


var input = document.getElementById('searchTextField');
var options = {

var autocomplete = new google.maps.places.Autocomplete(input,options);
//autocomplete.bindTo('bounds', map); 

google.maps.event.addListener(autocomplete, 'place_changed', function() {
  var place = autocomplete.getPlace();
    $("#results").append('<p> Latitude and Longtidute : '+place.geometry.location +'</p>');
    $("#results").append('<p> Address : '+place.formatted_address +'</p>');
    $("#results").append('<p> Places Name : ''</p>');

    var searchAddressComponents = place.address_components;
    $.each(searchAddressComponents, function(){

$ is defined by jQuery, which is an ordinary, 3rd-party library.

If you don't include it, it won't exist.


Try using jQuery instead $


jQuery('document').ready(function () {
    minDate: 0,
    beforeShowDay: $.datepicker.noWeekends,
    dateFormat: "dd-mm-yy"

Finally I figure it out after two days. My jsp page was load within the home page so home page also calling those from jquery inside the project. I removed my jsp's cdn and let home page to call those inside jquery. Thank you so much for your help all. Ps: I feel so stupid. :D


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.