~= called Attribute contains Word Selector .
Therefore, when you use: [attrName~=stuff] , it will correspond to each element with attrName equal to "stuff" or containing "stuff " , " stuff " or " stuff" . Examples:
- Selector:
[name~=ball] - Matches:
<input name="ball" type="text"><input name="ball " type="text"><input name=" ball" type="text"><input name=" ball " type="text"><input name="doesnotmatter ball asLongAsballIsBetweenWhiteSpaces" type="text">
*= called Attribute contains Substring Selector .
When you use [attrName*=stuff] , it will match if there is stuff in the attribute value, even if inside a word, for example:
- Selector:
[name*=ball] - Matches:
- All those that were matched
[name~=ball] , but also ... <input name="whatball" type="text"><input name="ballwhat" type="text"><input name="whatballwhat" type="text">- etc., as long as the attribute value contains the string
ball .
Note: the links above point to the jQuery site only because for these specific selectors I consider their links to be the best, but these attribute selectors are from CSS 2.1 and are supported with IE7 .
MSDN also calls the word selector Whitespace attribute selector .
Finally, click here for a demo fiddle .
acdcjunior
source share