Home > Article > Web Front-end > How jquery operates css to set color
How jquery operates css to set color: first use "$()" to obtain the HTML element node, and then use the css() method to operate css to set color; the specific syntax is "$("selector").css ("color/background-color","color value");".
The operating environment of this tutorial: windows7 system, jquery3.0.0 version, Dell G3 computer.
jquery operation css setting color
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-3.0.0.min.js"></script> <script> $(function() { $(".color1").css("color", "red"); $("#color2").css("background-color", "red"); }); </script> </head> <body> <ul> <li class="color1">测试文本</li> <li>测试文本</li> <li id="color2">测试文本</li> <li>测试文本</li> </ul> </body> </html>
Rendering:
##Description: The css() method sets or returns one or more style attributes of the selected element. The basic syntax is as follows:$(‘选择器’).css('属性名称','属性值');Recommended related video tutorials:
jQuery Tutorial (Video)
The above is the detailed content of How jquery operates css to set color. For more information, please follow other related articles on the PHP Chinese website!