Can jquery selector add comma?

青灯夜游
Release: 2022-03-16 14:50:19
Original
2453 people have browsed it

jquery selector can add commas. The group selector of jquery contains the English comma ",", and the syntax is "$("selector 1, selector 2, ..., selector n")", which is used to select multiple selectors at the same time, and It does the same thing.

Can jquery selector add comma?

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

Jquery selectors can add commas. This selector is called a "group selector".

jquery group selector

Group selector is used to perform the same operation on several selectors at the same time.

Syntax:

$("选择器1, 选择器2, ... , 选择器n")
Copy after login

The two selectors must be separated by English commas ,, otherwise the selector will not take effect.

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(function() {
				$("h3,div,p,span").css({"color":"red","background-color": "pink"});
			})
		</script>
	</head>
	<body>
		<h3>PHP中文网</h3> 
		<div>PHP中文网</div>
		<p>PHP中文网</p>
		<span>PHP中文网</span>
		
	</body>
</html>
Copy after login

Can jquery selector add comma?

$("h3,div,p,span").css({"color": "red","background-color": "pink"}) means to select all h3, div, p and span, and then define the font color of these elements as red and the background color as pink.

$(function() {
	$("h3,div,p,span").css({"color":"red","background-color": "pink"});
})
Copy after login

The above code is actually equivalent to:

$(function() {
	$("h3").css({"color":"red","background-color": "pink"});
	$("div").css({"color":"red","background-color": "pink"});
	$("p").css({"color":"red","background-color": "pink"});
	$("span").css({"color":"red","background-color": "pink"});
})
Copy after login

[Recommended learning: jQuery video tutorial, web front-end development]

The above is the detailed content of Can jquery selector add comma?. 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