jQuery将css类更改为div [英] jQuery changing css class to div

查看:111
本文介绍了jQuery将css类更改为div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个div元素为例,类'first'定义了许多css属性。

解决方案

我可以将css类'second'指派给同样的div, div>

  $(。first)。addClass(second); 

如果您想在活动中添加它,您也可以轻松地添加。点击事件的示例:

  $(。 (this).addClass(second); 
});


If I have one div element for example and class 'first' is defined with many css properties. Can I assign css class 'second' which also has many properties differently defined to this same div just on some event without writing each property in line.

解决方案

$(".first").addClass("second");

If you'd like to add it on an event, you can do so easily as well. An example with the click event:

$(".first").click(function() {
    $(this).addClass("second");
});

这篇关于jQuery将css类更改为div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆