ドキュメント

Selectors/attributeStartsWith

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

[attribute^=value]

Matches elements that have the specified attribute and it starts 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 an attribute name that starts with 'news' and puts text in them.

$("input[name^='news']").val("news here!");

<!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^='news']").val("news here!");
  });
  </script>
  
</head>
<body>
  <input name="newsletter" />
  <input name="milkman" />
  <input name="newsboy" />
</body>
</html>

NameType