Lucas Haas
Lucas Haas

Reputation: 341

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('');
        })

Upvotes: 11

Views: 43290

Answers (4)

Aditya Kapoor
Aditya Kapoor

Reputation: 1570

Use queue method (https://api.jquery.com/queue/) to queue your function calls in combination with delay.

$(formMessages)
  .addClass('error')
  .delay(3000)
  .queue(function(next){
    $(this).removeClass('error');
    next();
  })

Upvotes: 2

Rizwan
Rizwan

Reputation: 4433

Using Angular js you can use time function like this:

setTimeout(function(){
            var myE2 = angular.element( document.querySelector( '#compaignhiglighted' ) );
            myE2.removeClass('compaignhiglighted');
          }, 3000);

Upvotes: 0

giordanolima
giordanolima

Reputation: 1218

Using jquery...:

$(formMessages)
    .delay(3000) // its like settimeout
    .removeClass('error');

Reference: http://api.jquery.com/delay/

Upvotes: -2

prawn
prawn

Reputation: 2653

maybe something like...

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

Upvotes: 24

Related Questions