Home  >  Article  >  Web Front-end  >  How many types of selectors do jquery have?

How many types of selectors do jquery have?

青灯夜游
青灯夜游Original
2022-03-16 14:01:172137browse

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:

$(".类名")

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>

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!

Statement:
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