Get the next element with .next()

.next()


Description: Get the next element that follows the first matched element.


Example:

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>next demo</title>
      <script src="http://code.bitsycode.com/bitsycode-latest.min.js"></script>
      <style type="text/css">
         .active {
            background-color:yellow;
         }
      </style>
    </head>
    <body>
      
      <ul class="myList">
         <li class="active">One</li>
         <li>Two</li>
         <li>Three</li>
      </ul>
      
      <button onclick="next()">Next</button>
      
      <script>
        
        function next() {
            
            if ((bitsyCode(".active").next()).nodes.length > 0) {
                bitsyCode(".active").removeClass("active").next().addClass("active");
            } else {
                bitsyCode(".myList").last().removeClass("active");
                bitsyCode(".myList").first().addClass("active");
            }
            
        }
         
      </script>
     
    </body>
    </html>

Preview:

  • One
  • Two
  • Three
  • Usage

    • How to use:

      Get the next element that follows the first matched element.

    • USAGE:

      bitsyCode("element").next()
  • Options

    • What options are there:

      There are no options for this method.

  • Returns

    • Returns: the next element after the first matched element.
Share