ドキュメント

Selectors/attributeEndsWith

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

[attribute$=value]

Matches elements that have the specified attribute and it ends 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 "]". Varibles can be used using the following syntax: [name$='" +MyVar+ "']
Examples:

Finds all inputs with an attribute name that ends with 'letter' and puts text in them.

$("input[name$='letter']").val("a letter");

<!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$='letter']").val("a letter");
  });
  </script>
  
</head>
<body>
  <input name="newsletter" />
  <input name="milkman" />
  <input name="jobletter" />
</body>
</html>

NameType