0

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?

1
  • 3
    rel="stylesheet"? Commented Apr 1, 2017 at 12:15

3 Answers 3

3

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>
Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

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

Add script in this way

1 Comment

Please include some information as to why this is the correct answer. furthermore there are way more elegant ways to do this in laravel and your link does not work in the advertised laravel setup (since public should be the served root, so the link would be example.org/js/etc)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.