Reputation: 2172
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
Reputation: 618
<script src="<?php echo URL::to('/'); ?>/public/js/jquery-3.2.0.min.js"></script>
Add script in this way
Upvotes: -1
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
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