each

UK[i:tʃ] US[itʃ]

adj.each;respective

pron.each;respectively

jquery each() method syntax

Function: each() method specifies the function to be run for each matching element. Returning false can be used to stop the loop early.

Syntax: $(selector).each(function(index,element))

Parameters:

ParametersDescription
function(index,element) Required. Specifies the function to run for each matching element.
index The index position of the selector
element The current element (can also be used "this" selector)

jquery each() method example

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("li").each(function(){
      alert($(this).text())
    });
  });
});
</script>
</head>
<body>
<button>输出每个列表项的值</button>
<ul>
<li>Coffee</li>
<li>Milk</li>
<li>Soda</li>
</ul>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance