Home >Web Front-end >JS Tutorial >How jquery operates css to set color

How jquery operates css to set color

青灯夜游
青灯夜游Original
2021-04-28 18:10:073103browse

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>

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

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!

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