Home > Web Front-end > JS Tutorial > Detailed explanation of the use of jQuery selector [attribute*=value]

Detailed explanation of the use of jQuery selector [attribute*=value]

黄舟
Release: 2017-06-23 13:45:45
Original
1134 people have browsed it

Return value:Array[attribute*=value]

Overview

Match the given attributeSo elements that contain certain values

Parameters

attributeStringV1.0
Copy after login

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 contains 'man'

HTML code:

<input name="man-news" /> 
<input name="milkman" /> 
<input name="letterman2" /> 
<input name="newmilk" />
Copy after login

jQuery Code:

$("input[name*=&#39;man&#39;]")
Copy after login

Result:

[ <input name="man-news" />, <input name="milkman" />, <input name="letterman2" /> ]
Copy after login

This selector matches elements whose given attribute contains certain values.

Grammar structure:

$("[attribute*=value]")
Copy after login

Parameter list:

Detailed explanation of the use of jQuery selector [attribute*=value]

Example code:

Example one:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.jb51.net/" />
<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*=&#39;ir&#39;]").css("color","blue"); 
  })
})
</script>
</head>
<body>
<ul>
  <li id="first">html专区</li>
  <li id="second">Jquery专区</li>
</ul>
<button>点击查看效果</button>
</body>
</html>
Copy after login

The above code can set the text color of the li element with "ir" in the id attribute value to blue.

Example 2:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.jb51.net/" />
<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>
Copy after login

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 Detailed explanation of the use of jQuery selector [attribute*=value]. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template