jQuery .nextAll() gets all following siblings of each element in the set of matched elements

Syntax and Description

.nextAll([selector])

gets all following siblings of each element in the set of matched elements, optionally filtered by a selector. selector (optional) is a string containing a selector expression to match elements against.

Its return value is the new jQuery object.

Search tags from nextAll()

The following code selects disabled buttons and then search span tags from nextAll().


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!-- w  ww.j av  a  2 s. c om-->
             $("button[disabled]").nextAll("span").text("data");
        });
    </script>
    <style>
      .y { background:yellow; }
  </style>

  </head>
  <body>
    <body>
       <div><button disabled="disabled">First</button> - <span class="selected"></span>
            <span></span>
       </div>

  </body>
</html>

Click to view the demo

Add style from the second

The following code select first div tag from the document and calls nextAll() method to get the rest..


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--from w  w w .ja  va2  s . c  o m-->
              $("div:first").nextAll().css("color","red");
        });
    </script>
  </head>
  <body>
    <body>
          <div>java2s.com</div>
          <div>j ava2s.com</div>
    </body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities