Home >Web Front-end >JS Tutorial >How to apply jQuery [attribute*=value] selector?
Return value:Array
Overview
Match the given attribute is an element ending with some value
Parameter
attributeStringV1.0
Attribute name
value StringV1. 0
Attribute value. Quotes are optional in most cases. But it is used to avoid conflicts when the attribute value contains "]".
Example
Description:
Find all input elements whose name ends with 'letter'
HTML code:
<input name="newsletter" /> <input name="milkman" /> <input name="jobletter" />
jQuery Code:
$("input[name$='letter']")
Result:
[ <input name="newsletter" />, <input name="jobletter" /> ]
The code is as follows:
$("[attribute*=value]")
Parameter list:
Example code:
Example 1:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.bitsCN.com/" /> <title></title> <script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("li[id*='ir']").css("color","blue"); }) }) </script> </head> <body> <ul> <li id="first">html专区</li> <li id="second">Jquery专区</li> </ul> <button>点击查看效果</button> </body> </html>
The above code can set the text color of the li element with "ir" in the id attribute value is blue.
Example 2:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.bitsCN.com/" /> <title></title> <script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("li[id*=[ir]").css("color","blue"); }) }) </script> </head> <body> <ul> <li id="f[irst">html专区</li> <li id="second">Jquery专区</li> </ul> <button>点击查看效果</button> </body> </html>
From the above code, we can see how when the code contains "[" or "]", it must be enclosed in quotation marks, otherwise it will cause a matching error.
The above is the detailed content of How to apply jQuery [attribute*=value] selector?. For more information, please follow other related articles on the PHP Chinese website!