开发者

re-apply css classes using jquery

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.

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 th开发者_高级运维e class values back to the element that's been modified?

Thanks for any help


if you are only having width and height modified try

$('.mydivclass').css({width: '', height: ''})


Check out 'addClass' and 'removeClass':

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

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.


I have no idea how you're persisting the changes but if you are using the style attribute to keep the changes you can do something like this

$('div').removeAttr('style');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜