I'm trying to run a function on the selector that addClass was just ran on after addClass is pleted.
This way made sense to me, but it doesn't seem to be working:
$('.focused').addClass('fadeOutDown', function(){ $(this).remove(); });
How can I run a function after I've ran the addClass function on the same selector?
Chaining runs it at the same time and I haven't tried a set-timeout, but that seem inefficient.
I'm trying to run a function on the selector that addClass was just ran on after addClass is pleted.
This way made sense to me, but it doesn't seem to be working:
$('.focused').addClass('fadeOutDown', function(){ $(this).remove(); });
How can I run a function after I've ran the addClass function on the same selector?
Chaining runs it at the same time and I haven't tried a set-timeout, but that seem inefficient.
Share Improve this question asked Dec 9, 2013 at 4:31 gomangomangogomangomango 6911 gold badge10 silver badges31 bronze badges 9-
Class is added instantly after
$('.focused').addClass('fadeOutDown');
– zerkms Commented Dec 9, 2013 at 4:34 - addClass is synchronous, you don't need callback here. – Ram Commented Dec 9, 2013 at 4:34
- @zerkms I know the class is added instantly. I'm trying to run a function after. – gomangomango Commented Dec 9, 2013 at 4:35
- 2 @gomangomango: put it on the next line. JS is evaluated line by line. The next line is evaluated right after the previous. – zerkms Commented Dec 9, 2013 at 4:35
- @undefined what does synchronous mean? Then how do I remove the same element that I added the class to after like I am trying to do? – gomangomango Commented Dec 9, 2013 at 4:36
1 Answer
Reset to default 4Try to do this way :
$('.focused').addClass('fadeOutDown');
setTimeout(function() {
$('.focused').remove();
}, 2000);
// make sure you provide appropriate time i.e after you get the effect