Attribute contains ([foo*=bar])
In this chapter you will learn:
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><!--from j av a 2 s . c om-->
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("input[name*='Abc']").val("Abc");
});
</script>
</head>
<body>
<input name="Abc" />
<input name="Bcd" />
<input name="Cde" />
</body>
</html>
Next chapter...
What you will learn in the next chapter:
- Description and Syntax for attribute contains word selector
- Examples for attribute contains word selector