Home > Web Front-end > JS Tutorial > body text

How jquery operates css to set color

青灯夜游
Release: 2023-01-05 16:12:37
Original
3096 people have browsed it

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");".

How jquery operates css to set color

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>
Copy after login

Rendering:

How jquery operates css to set color

##Description:

The css() method sets or returns one or more style attributes of the selected element. The basic syntax is as follows:

$(‘选择器’).css(&#39;属性名称&#39;,&#39;属性值&#39;);
Copy after login
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!

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