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.
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")
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>
$("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"}); })
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"}); })
[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!