The jQuery toggle() Method is part of the jQuery core and a useful method for toggling between jQuery hide() and show(). In a recent use case, we needed to provide a simple way for a client to see how their site would look with or without background images and so we wrote up a very simply jQuery snippet to Toggle a CSS Background on a button/link click. Here's how: -
The target in this instance is the element with class "target-class" so simply change this to your own target / div. Now when you click the link with class 'toggle-class' the element will toggle the class 'no-bg' which you can also change to suit your needs.
Join in the Discussion