开发者

Is there a "revert" or "restore" function in jQuery?

Say I make a function that on-click changes div color, is there a function that on another click, restores the div 开发者_如何学编程to it's default or previous color, before the change? (without having to specify what was the previous color)


You can use .toggleClass() to add/remove a CSS class, and specify the color in your CSS.


Not that I know of, although I trust there are ways around this. Easiest one that comes to mind would be to either add and remove a class specifies a color OR add the color with .css('color','red') say and then remove the style attribute .removeAttr('style').

The latter would only work if you aren't adding with multiple styles and only wanting to remove one. The former would work in this case provide you are happy to set up a class for each style combination/possibility.

Personally I always try to use classes to change visual aspects of webpages so that would be my preference

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜