Home >Web Front-end >Front-end Q&A >How many types of selectors do jquery have?
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.
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>
$(".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!