jQuery attribute contains selector
Description and Syntax
$('[foo*=bar]')
selects all elements that have the
foo
attribute with a value containing the substring bar
.
Examples
Selector | Selects |
---|---|
$('[style*=background]') | all elements that have a style value containing background |
$('a[href*=java2s.com]') | all <a> elements that have an href value containing java2s.com |
$('p[class*=my]') | <p class="yourclass myclass">text</p> , <p class="myclass yourclass">text</p> and <p class="thisismyclass">text</p> . |
The following code select input element
whose name
attribute has value Abc
.
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!-- w w w .j av a 2 s .c om-->
$("input[name*='Abc']").val("Abc");
});
</script>
</head>
<body>
<input name="Abc" />
<input name="Bcd" />
<input name="Cde" />
</body>
</html>