屬性包含前置字元選擇器 [name|=”value”]


attributeContainsPrefix 選擇器

說明: 選取具有指定屬性,其值等於給定字串或以該字串開頭,後接連字號 (-) 的元素。

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

    attribute: 屬性名稱。

    value: 屬性值。可以是 有效識別碼 或帶引號的字串。

此選擇器引入 CSS 規格中,用於處理語言屬性。

範例

找出所有具有 hreflang 屬性且為英文的連結。

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.jquery.com/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>

示範