Home > Web Front-end > Front-end Q&A > How many types of selectors do jquery have?

How many types of selectors do jquery have?

青灯夜游
Release: 2022-03-16 14:01:17
Original
2183 people have browsed it

In jquery, there is only one class selector, which is used to select elements with specified class attribute values ​​and perform various operations on the elements; syntax "$(".class name")", class name (That is, the value of the class attribute) must be preceded by a prefix ".", otherwise the selector will not take effect.

How many types of selectors do jquery have?

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

In jquery, there is only one type of class selector.

Class selector, also known as "class selector", is used to select elements with specified class attribute values.

We can define the same class for "the same element" or "different element", and then perform various operations on the elements of this class.

Syntax:

$(".类名")
Copy after login

The class name (that is, the value of the class attribute) must be preceded by a prefix English period ., otherwise the selector will not take effect. An English period . is added in front of the class name to indicate that this is a class selector.

Example:

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

How many types of selectors do jquery have?

$(".lv").css("color","red") means selected class="lv", and then define the color of these elements as red.

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

The above is the detailed content of How many types of selectors do jquery have?. 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