Search code examples
javascriptjquerytimeout

Remove class after 3 seconds


I'd like to put a timeout function to remove these two classes, but I have no idea how to do that. Can anyone help me how to include a timeout here? Thanks in advance.

.done(function(response) {
            // Make sure that the formMessages div has the 'success' class.
            $(formMessages).removeClass('error');
            $(formMessages).addClass('success');

            // Set the message text.
            $(formMessages).text('Message sent!');

            // Clear the form.
            $('#name').val('');
            $('#email').val('');
            $('#message').val('');
            //$('#budget').val('');
        })

Solution

  • maybe something like...

     setTimeout(function(){
                $(formMessages).removeClass('error');
                //....and whatever else you need to do
        }, 3000);