Search code examples
laravelmaterialize

Laravel materialize css dropdown menu not working


In my project the dropdown menu won't work.

the code is like this:

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
{!! MaterializeCSS::include_full() !!}
<script>
    $( document ).ready(function() => {
        $('.dropdown-button').dropdown();
    });  
</script>
<title>...</title>
</head>

this is the header of the page

this is what the dropdown look like

      <ul id="dropdown1" class="dropdown-content">
        <li><a href="#!">one</a></li>
        <li><a href="#!">two</a></li>
        <li class="divider"></li>
        <li><a href="#!">three</a></li>
      </ul>
      <nav>
        <div class="nav-wrapper">
          <a href="#!" class="brand-logo">Logo</a>
          <ul class="right hide-on-med-and-down">
            <li><a href="sass.html">Sass</a></li>
            <li><a href="badges.html">Components</a></li>
            <!-- Dropdown Trigger -->
            <li><a class="dropdown-trigger" href="#!" data-target="dropdown1">Dropdown<i class="material-icons right">arrow_drop_down</i></a></li>
          </ul>
        </div>
      </nav>

I put materialize css into my project using composer, and did what was listed on the official materialize website

I hope someone can help me out


Solution

  • Try and move your script (the one below) to the bottom of your body.

    <script>
        $( document ).ready(function() => {
            $('.dropdown-button').dropdown();
        });  
    </script>