Reputation: 1339
I want to remove a class of a DIV element that is created as soon as a function is called.
The thing is that I want to have the .removeClass
also be part of that function.
This is the function I have now.
function user_message(msg) {
var html = '<div class="user-reply FadeElement" style="display: flex;">'+
msg.text + '</div>';
return html;
}
I have tried adding the .removeClass
function inside the user_message
function
function user_message(msg) {
var html = '<div class="user-reply FadeElement" style="display: flex;">'+
msg.text + '</div>';
return html;
$('.user-reply').removeClass('FadeElement');
}
but it doesn't work.
Perhaps I can add the $('.user-reply').removeClass('FadeElement');
everywhere the user_message
function is called, but I was wondering if there is a way to do it inside the function
The user_message
function is called like this.
$("#user-window").append(user_message( value ));
Upvotes: 0
Views: 23
Reputation: 316
First of all, it wont work because you are returning the result before even removing the class.
Second, you can add a timeout (if that might resolve your issue):
function user_message(msg) {
var html = '<div class="user-reply FadeElement" style="display: flex;">'+
msg.text + '</div>';
setTimeout(function(){
$('.user-reply').removeClass('FadeElement');
},1000);
return html;
}
Upvotes: 1