I have a material css carousel, and I am trying to hide the back button on the first slide. I attempted to use the code below from a previous post
The following code snippet prevents the user from looping through the carousel indefinitely.
Stop looping in Carousel materializecss
$('.carousel').carousel({fullWidth: true});
function forward(){
if ($('.carousel-item.active').next().is('.carousel-item')) {
$('.carousel').carousel('next');
} else {
alert('last');
}
}
function backward(){
if ($('.carousel-slider .carousel-item').first().is('.active')) {
alert('first')
} else {
$('.carousel').carousel('prev');
}
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
<div class="carousel carousel-slider center" data-indicators="true">
<div class="carousel-fixed-item center">
<a class="btn waves-effect white grey-text darken-text-2">button</a>
</div>
<div class="carousel-item red white-text" href="#one!">
<h2>First Panel</h2>
<p class="white-text">This is your first panel</p>
</div>
<div class="carousel-item amber white-text" href="#two!">
<h2>Second Panel</h2>
<p class="white-text">This is your second panel</p>
</div>
<div class="carousel-item green white-text" href="#three!">
<h2>Third Panel</h2>
<p class="white-text">This is your third panel</p>
</div>
<div class="carousel-item blue white-text" href="#four!">
<h2>Fourth Panel</h2>
<p class="white-text">This is your fourth panel</p>
</div>
</div>
<nav>
<div class="nav-wrapper grey darken-2">
<ul class="left">
<li><a onclick="backward()">Back</a></li>
<li><a onclick="forward();">Next</a></li>
</ul>
</div>
</nav>