ドキュメント

Core/eq

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Core

eq( position )

Reduce the set of matched elements to a single element.
The position of the element in the set of matched elements starts at 0 and goes to length - 1; passing an out-of-range index returns an empty jQuery object.
Arguments:
positionNumber
The index of the element to select.
Examples:

Reduces the selection to the second selected element.

$("p").eq(1).css("color", "red")

<!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(){
    $("p").eq(1).css("color", "red")
  });
  </script>
  
</head>
<body>
  <p>This is just a test.</p><p>So is this</p>
</body>
</html>

NameType