ドキュメント

Selectors/attributeEquals

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

[attribute=value]

Matches elements that have the specified attribute with a certain value.
Arguments:
attributeString
An attribute name.
valueString
An attribute value. Quotes are optional in most cases, but should be used to avoid conflicts when the value contains characters like "]". Variables can be used using the following syntax: [name='" +MyVar+ "']
Examples:

Finds all inputs with name 'newsletter' and changes the text of the span next to it.

$("input[name='newsletter']").next().text(" is newsletter");

<!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(){
    $("input[name='newsletter']").next().text(" is newsletter");
  });
  </script>
  
</head>
<body>
  <div>
    <input type="radio" name="newsletter" value="Hot Fuzz" />
    <span>name?</span>
  </div>
  <div>
    <input type="radio" name="newsletters" value="Cold Fusion" />
    <span>name?</span>
  </div>
  <div>
    <input type="radio" name="accept" value="Evil Plans" />
    <span>name?</span>
  </div>
</body>
</html>

NameType