Home  >  Article  >  Web Front-end  >  How to modify css style in jquery

How to modify css style in jquery

青灯夜游
青灯夜游Original
2021-05-20 17:02:2516079browse

How to modify the css style in jquery: 1. Use the "css("property name", "property value")" statement to modify; 2. Use "css({property name: "property value", property Name: "Attribute Value"...})" statement modification; 3. Use the "toggleClass("Class Name")" statement to modify it.

How to modify css style in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.

How to modify css style with JQuery

css part:

.div1{
      width:100px;
      height:100px;
      background:#00ff00;
      }
.div2{
       width:100px;
       height:100px;
       background:#ff0000;
      }#Btndiv{
         width:100px;
         height:100px;
         border: 1px solid #ccc;
         margin-bottom: 10px;
         }

jQuery code:

<div id="Btndiv" onclick="changeCss()"></div>
        <script>
            $(document).ready(function (){
                //第一种
//                $("div").css("width","100px");
//                $("div").css("height","100px");
//                $("div").css("background","cyan");
                //第二种
//                $("div").css({
//                    width:"100px",height:"100px",background:"red"
//                });
                //第三种
                $("div").addClass("div1");
                $("div").click(function (){
//                    $(this).addClass("div2");
//                  $(this).removeClass("div1");
                    $(this).toggleClass("div2");
                });
            });
    </script>

Related video tutorial recommendations:jQuery Tutorial(Video)

The above is the detailed content of How to modify css style in 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