Home >Web Front-end >JS Tutorial >How to change css style with jquery

How to change css style with jquery

青灯夜游
青灯夜游Original
2021-04-28 16:16:453504browse

Jquery method to change css style: first use "$()" to get the HTML element node, and then use the css() method to change the css style; the specific syntax is "$("selector").css(" attribute Name","property value");".

How to change css style with jquery

The operating environment of this tutorial: windows7 system, jquery3.0.0 version, Dell G3 computer.

In jquery, you can use the css() method to change the css style.

The css() method sets or returns one or more style attributes of the selected element.

The basic syntax is as follows

$(‘选择器’).css('属性名称','属性值');

Example:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
    <script>
      $(function() {
        $(".big").css("font-size", "30px");
        $("#color").css("color", "red");
      });
    </script>
  </head>
  <body>
    <ul>
      <li class="big">测试文本</li>
      <li>测试文本</li>
      <li id="color">测试文本</li>
      <li>测试文本</li>
    </ul>
  </body>
</html>

Rendering:

How to change css style with jquery

Related Recommended video tutorial: jQuery Tutorial (Video)

The above is the detailed content of How to change css style with jquery. 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