Add list next add class

In this example below you will see how to do a Add list next add class with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by emrankhan016, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright emrankhan016 ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Add list next add class</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <ul class="list">
  <li class="current">1</li>
  <li class="cls2">2</li>
  <li class="cls3">3</li>
  <li class="cls4">4</li>
  <li class="cls5">5</li>
  <li class="cls6">6</li>
  <li class="cls7">7</li>
</ul>
 
<a href="#" id="next">next</a>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/emrankhan016/add-list-next-add-class-EvdpvV */
.current{color:red;}
 

/*Downloaded from https://www.codeseek.co/emrankhan016/add-list-next-add-class-EvdpvV */
$(document).ready(function(){ 
  // Add cuttent class
  var $lis = $('.list li'); 
  $("#next").click(function () {
    var $selected = $('.current').removeClass('current');
    ($selected.next().length > 0 ? $selected.next() : $lis.first()).addClass('current');
  }); 
});

Comments