Attribute Contains Prefix Selector [name|=value]

attributeContainsPrefix selector

version added: 1.0jQuery('[attribute|=value]')

  • attribute
    一个属性名.
    value
    一个属性值,引号是可选的.

描述: 选择指定属性等于给定字符串或以该字符串为前缀(该字符串后跟一个连字符“-” )的元素。

这个选择器是引入CSS规范来处理语言属性。

Example:

Finds all links with an hreflang attribute that is english.

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  
  <a href="example.html" hreflang="en">Some text</a> 

  <a href="example.html" hreflang="en-UK">Some other text</a>
  
<script>$('a[hreflang|=en]').css('border','3px dotted green');</script>

</body>
</html>

Demo:

jQuery 1.6 API 中文版Clove整理、修订