M_Idrees
M_Idrees

Reputation: 2172

PHP Laravel - jQuery not working - ReferenceError: $ is not defined

I created a fresh Laravel project and added jquery file at:

rootproject/public/js/jquery-3.2.0.min.js

Now in welcome.blade.php, in html header tag I am referencing it as:

<link href="{{ asset('/js/jquery-3.2.0.min.js') }}" rel="stylesheet">

And put an alert() message in document load function.

$( document ).ready(function() {
  alert("my message");
});

But its not working. In console log it is showing error message:

ReferenceError: $ is not defined

Can anybody suggest how to fix it?

Upvotes: 0

Views: 1852

Answers (3)

Haninder Singh
Haninder Singh

Reputation: 618

<script src="<?php echo URL::to('/'); ?>/public/js/jquery-3.2.0.min.js"></script>

Add script in this way

Upvotes: -1

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

You are including JS file in CSS way:

<link href="{{ asset('/js/jquery-3.2.0.min.js') }}" rel="stylesheet">

that's the issue. Replace it with:

<script src="{{ asset('js/jquery-3.2.0.min.js') }}"></script>

every thing will be fine.

Upvotes: 2

alaric
alaric

Reputation: 987

Replace

<link href="{{ asset('/js/jquery-3.2.0.min.js') }}" rel="stylesheet">

with:

<script src="{{ asset('js/jquery-3.2.0.min.js') }}"></script>

Upvotes: 3

Related Questions