Home >Web Front-end >JS Tutorial >How to modify css style in jquery
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.
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!