ドキュメント

Selectors/next

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

prev + next

Matches all next elements specified by "next" that are next to elements specified by "prev".
Arguments:
prevSelector
Any valid selector.
nextSelector
A selector to match elements that are next to the first selector.
Examples:

Finds all inputs that are next to a label.

$("label + input").css("color", "blue").val("Labeled!")

<!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(){
    $("label + input").css("color", "blue").val("Labeled!")
  });
  </script>
  
</head>
<body>
  <form>
    <label>Name:</label>
    <input name="name" />
    <fieldset>
      <label>Newsletter:</label>
      <input name="newsletter" />
    </fieldset>
  </form>
  <input name="none" />
</body>
</html>

NameType