DEV Community

loading...

Discussion on: JQuery: I have a problem with a changement of class on click

Collapse
paxfeline profile image
David Newberry • Edited

As has already been suggested, you want to use setTimeout.

A couple other things: instead of using a third CSS class, you can add and then remove the second background. Also, you can consolidate how things are set up quite a bit. Attach one handler to document.ready, which sets up your click handlers. Then you can set up the immediate and the delayed actions at once.

I had to tinker with the code a bit to get a copy that would run without reference to your images in the CSS, but everything is basically the same. Here's the code with the changes I'd suggest: pastebin.com/JRiixP7e