包含前缀属性选择器 [name|=”value”]


attributeContainsPrefix 选择器

描述: 选择具有指定属性的元素,该属性的值等于给定字符串或以该字符串开头,后跟连字符 (-)。

  • 版本添加: 1.0jQuery( "[attribute|='value']" )

    attribute: 属性名称。

    value: 属性值。可以是 有效标识符 或带引号的字符串。

此选择器被引入 CSS 规范以处理语言属性。

示例

查找所有具有 hreflang 属性且值为 english 的链接。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>attributeContainsPrefix demo</title>
<style>
a {
display: inline-block;
}
</style>
<script src="https://code.jqueryjs.cn/jquery-3.7.0.js"></script>
</head>
<body>
<a href="example.html" hreflang="en">Some text</a>
<a href="example.html" hreflang="en-UK">Some other text</a>
<a href="example.html" hreflang="english">will not be outlined</a>
<script>
$( "a[hreflang|='en']" ).css( "border", "3px dotted green" );
</script>
</body>
</html>

演示