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

How to modify css style in jquery

青灯夜游
Release: 2023-01-06 11:14:42
Original
16166 people have browsed it

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

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

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!

Related labels:
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
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template