jQuery CSS

通过jQuery,可以对CSS元素进行操作。

addClass()

向被选元素添加一个或多个类

removeClass()

从被选元素删除一个或多个类

toggleClass()

对被选元素进行添加/删除类的切换操作

css()

设置或返回样式属性

 

.important
{
        font-weight:bold;
        font-size:xx-large;
} 
.blue
{
        color:blue;
}

  

$("button").click(function(){
  $("h1,h2,p").addClass("blue");
  $("div").addClass("important");  --> addClass也可以同时添加多个类$("body div:first").addClass("important blue");
$("h1,h2,p").removeClass("blue");
$("h1,h2,p").toggleClass("blue"); --> 该方法对被选元素进行添加、删除类的切换操作
});

 

获得属性
$("p").css("background-color");

设置属性
$("p").css({"background-color":"yellow","font-size":"200%"});

  

posted on 2020-04-23 10:27  青柠锦鲤  阅读(186)  评论(0编辑  收藏  举报