0

I have laravel layout

<html> //layout.blade.php
    <head>
        <script src="/js/jquery.js"></script>
        <script src="/js/jquery-ui.js"></script>
    </head>
    <body>
         @yield("content")
    </body>
</html>

And my view

@extends("layout")

@section("content")
<ul class="test">
    <li>1</li>
    <li>2</li>
</ul>

<script>
     $(function() {
         $(".test").selectable();
     });
</script>
@endsection

My browser console always show me $(...).selectable is not a function

But if i make same without layout or without anonymous function this works

3
  • can you see the scripts in the browser? Commented Jul 7, 2018 at 19:25
  • Do you have the js folder directly in the public folder? Commented Jul 7, 2018 at 19:26
  • Yes i can in head tag, jquery work normal Commented Jul 7, 2018 at 19:26

2 Answers 2

2

I think location is changed, because of route. So you'd better to specify the correct url of "public" folder.

Please change like this.

<html> //layout.blade.php
    <head>
        <script src="{{URL::Asset('/js/jquery.js')}}"></script>
        <script src="{{URL::Asset('/js/jquery-ui.js')}}"></script>
    </head>
    <body>
         @yield("content")
    </body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

0

As mentioned in the above question this kind of problem usually arises when you try to pass an argument or route variable. So it would be wise to use asset() or secure_asset() while using your resources in the page.

<html> //layout.blade.php
    <head>
        <script src="{{ asset('js/jquery.js') }}"></script>
        <script src="{{ asset('js/jquery-ui.js') }}"></script>
    </head>
    <body>
         @yield("content")
    </body>
</html>

Also please check the network section of your browser to make sure your resources are loading perfectly.

Comments

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.