jquery 遍历 nextAll([expr])

nextAll([expr])

得到匹配元素集合中各个元素后端的所有兄弟元素集合。返回匹配元素集合

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    $("div:first").nextAll().addClass("after");
  });
  </script>
  <style>
  div { width: 80px; height: 80px; background: #abc; 
        border: 2px solid black; margin: 10px; float: left; }
  div.after { border-color: red; }
  </style>
</head>
<body>
  <div>first</div>
  <div>sibling<div>child</div></div>
  <div>sibling</div>
  <div>sibling</div>
</body>
</html>

 

$("div:first").nextAll().addClass("after");
得到匹配div元素集合后所有的兄弟元素集合。以下是匹配元素集合

<div>sibling</div>
<div>sibling</div>
<div>sibling</div>

你可能感兴趣的:(html,jquery)