Using delay() with removeClass()

remove class after delay javascript
jquery delay
javascript remove class delay
jquery settimeout
delay in javascript
remove class after 5 seconds jquery
jquery delay addclass
settimeout not working

How do I delay the removal of a css class in jQuery?

Here is my code

$(this).addClass("uk-form-danger").delay(5000).removeClass("uk-form-danger");

The above code does nothing. I can add the class with the following code

$(this).addClass("uk-form-danger");

and I can remove it with

$(this).removeClass("uk-form-danger");

but I can't delay the removal of the class.

You can easily accomplish that with a setTimeout:

var myItem = $(this);

myItem.addClass("uk-form-danger");
setTimeout( function(){ myItem.removeClass("uk-form-danger"); }, 5000 );

.delay() not working on .removeClass() ?, delay(1000).removeClass().addClass(text); };. I would like the remove the current class (and add the new class) just before the scroll animation  .delay() only works for methods in the effects queue. You need to place your .addClass() and .removeClass() into the default effects queue by including a duration. $(this).addClass("uk-form-danger", 250).delay(5000).removeClass("uk-form-danger", 250);

jquery delay is only intended to use with animations, you will not be able to delay the removeClass this way, use setTimeout instead:

var $el = $('#myId');
$el .addClass("uk-form-danger")
setTimeout(function(){
    $el .removeClass("uk-form-danger");
}, 5000);

Using $().delay(9000).removeClass() but there's , Shouldn't there be a 9 second delay before .removeClass('transition') is run? $(​function() { $( "#button" ).click(function() { $('#writing').addClass('transition', 1000​  .delay() is only designed to work with animations. You'll have to resort to using regular setTimeouts for what you're doing: You'll have to resort to using regular setTimeouts for what you're doing: hope it fit your need :)

Try something like this using setTimeout

var self = $(this);
self.addClass('uk-form-danger');
setTimeout(function () {
    self.removeClass('uk-form-danger');
}, 5000);

remove class after delay in jQuery, To remove class after delay in jQuery you can use one of the snippet below. Samples. jQuery Sample using setTimeout(). If you dont use setTimeout, then that delay wont work – Alex Jolig Feb 6 at 4:32 The solution doesn't need both to work together. Either use delay() with queue() in jQuery or simply use setTimeout() can solve the problem.

Have you tried using setTimeout instead of delay?

var myObject = $(this);

myObject.addClass("uk-form-danger");

setTimeout(function()
{
    myObject.removeClass("uk-form-danger");
}, 5000);

How to Add/Remove Classes After Delay, Use this jQuery snippet to add or remove a class from your HTML setTimeout() method creates a function that will remove the blue class from the header element after 4000 milliseconds. removeClass() method for the . So, .removeClass() can be used on XML or SVG documents. More than one class may be removed at a time, separated by a space, from the set of matched elements, like so:

The easiest way is to use jQueryUI.

.delay() only works for methods in the effects queue. You need to place your .addClass() and .removeClass() into the default effects queue by including a duration.

$(this).addClass("uk-form-danger", 250).delay(5000).removeClass("uk-form-danger", 250);

How to remove class from an element after delay using jQuery, I'm having problems combining .delay with .addClass using jQuery. My goal is to have a slight delay before the class is added, but my approach doesn't seem to solve the issue. $(“div”).stop().animate({top:'0′}, 600); .com/questions/​4954814/delayed-addclass-remove-class-function-not-working). How to use addClass () and removeClass () to remove one class name, and add a new class name. Using a function to remove a class from the selected elements. How to remove several class names from the selected elements.

Delay .addClass with jQuery?, $('.animated-selector').addClass('hidden').stop().delay(500).queue(function(){. $(​this).removeClass('hidden');. }); Sign up for free to join this conversation on  I need to add a delay to .addClass and .removeClass for 200ms here: Can I call delay() between addClass() and such? but the structure there is slightly different.

jQuery Add Class, Delay, Remove Class · GitHub, Definition and Usage. The delay() method sets a timer to delay the execution of the next item in the queue.

Comments
  • This wont work. What do you thing 'this' is inside the timeout function's scope?
  • This wont work. What do you thing 'this' is inside the timeout function's scope?
  • Then you just create a variable and store it there, then refer to it likeso: var myObject = $(this); myObject.removeClass("uk-form-danger");
  • Well... that would be correct. But your answer is not doing that.