Ajay Kulkarni Ajay Kulkarni - 6 months ago 16
Javascript Question

Side-nav doesn't work in material design based mobile app

I wrote a simple page with side-nav functionality. However side-nav fails to open up when clicked on top left corner. My code:

Html:


<nav>
<ul class="right hide-on-med-and-down">
<li><a href="#!">First Sidebar Link</a></li>
<li><a href="#!">Second Sidebar Link</a></li>
</ul>
<ul id="slide-out" class="side-nav">
<li><a href="#!">First Sidebar Link</a></li>
<li><a href="#!">Second Sidebar Link</a></li>
</ul>
<a href="#" data-activates="slide-out" class="button-collapse"><i class="mdi-navigation-menu"></i></a>
</nav>


<div class="row">
<div class="card logincard">
<form class="col s12">
<h5>Enter your mail id to reset your password: </h5>
<div class="row">
<div class="input-field col s12">
<input id="mail" type="email" class="validate">
<label for="mail">Mail</label>
</div>
</div>
<div class="row">
<a class="waves-effect waves-light btn" style="background: #4099FF;">Submit</a>
</div>
</form>
</div>
</div>


JS:


(function($){
$(function(){

$('.button-collapse').sideNav();

}); // end of document ready
})(jQuery); // end of jQuery name space


JSFiddle link is: https://jsfiddle.net/0hq4g3f1/

How can I fix it?

Answer

You need to place your icon (or something) inside a class left UL

<nav>
  <ul class="left show-on-med-and-down">
    <li><a href="#" data-activates="slide-out" class="button-collapse"><i class="mdi-navigation-menu"></i></a></li>
  </ul>
  <!-- etc -->