ドキュメント

Selectors/attributeContains

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

[attribute*=value]

Matches elements that have the specified attribute and it contains 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 a name attribute that contains 'man' and sets the value with some text.

$("input[name*='man']").val("has man in it!");

<!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*='man']").val("has man in it!");
  });
  </script>
  
</head>
<body>
  <input name="man-news" />
  <input name="milkman" />
  <input name="letterman2" />
  <input name="newmilk" />
</body>
</html>

NameType