jQuery: The Write Less, Do More JavaScript Library

Selectors/attributeMultiple

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

[selector1][selector2][selectorN]

Matches elements that have the specified attribute and it contains a certain value.
Arguments:

selector1Selector
An attribute selector.
selector2Selector
Another attribute selector, reducing the selection even more
selectorN (Optional)Selector
As many more attribute selectors as necessary

Examples:
Finds all inputs that have an id attribute and whose name attribute ends with man and sets the value.

$("input[id][name$='man']").val("only this one");

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="../jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    $("input[id][name$='man']").val("only this one");
  });
  </script>
  
</head>
<body>
  <input id="man-news" name="man-news" />
  <input name="milkman" />
  <input id="letterman" name="new-letterman" />
  <input name="newmilk" />
</body>
</html>

NameType