使用jquery重新应用css类 [英] re-apply css classes using jquery

查看:104
本文介绍了使用jquery重新应用css类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个页面上有很多div,其高度和宽度根据用户而改变。是否有一个简单的方法将样式恢复到css页面中的默认值,而不实际刷新页面。

I have many divs on a page that the height and width are altered based on the user. Is there an easy way to restore the styles back to the default value in the css page itself without actually refreshing the page.

我知道我可以手动应用的高度和宽度回到默认值,但不知道是否有一个方法有jquery应用类值返回到已修改的元素?

I know I could manually apply the height and width back to the default, but didn't know if there was a way to have jquery apply the class values back to the element that's been modified?

感谢任何帮助

推荐答案

out'addClass'and'removeClass':

Check out 'addClass' and 'removeClass':

$('.the_div').removeClass('defaultStyle').addClass('defaultStyle');

这样会将样式重置为defaultStyle类。你也可以只设置 attr('class','defaultStyle'),但这也会删除你在同一个div上的任何其他类。

That will reset the style to the defaultStyle class. You could also just set attr('class', 'defaultStyle'), but this will also remove any other classes you have on the same div.

这篇关于使用jquery重新应用css类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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