When I use load my flash message doesn’t disappear

I am trying to make a “widget” inside a home screen. And this “widget” will display messages depending on the user’s actions with it.

I don’t want to reload the entire page, since there may be another “widget” with user information that I haven’t finished filling in. So I’ve been getting by doing a load.

$('#user_credit .card-body #message').load(' #user_credit .card-body #message');

Now with this code the flash appears, either that it has been done correctly or if there has been an error.

The problem is that this message does not disappear automatically.

I’ve gotten it to go away using a timer in JS.

setTimeout(() => {  $("#message").attr('style', 'display:none') }, 2000);

But now it doesn’t show up again. So I had to add another timer.

setTimeout(() => {  $("#message").attr('style', 'display:block') }, 100);

In the end the code is like this:

$('#user_credit .card-body #message').load(' #user_credit .card-body #message');
setTimeout(() => {  $("#message").attr('style', 'display:block') }, 100);
setTimeout(() => {  $("#message").attr('style', 'display:none') }, 2000);

With all this it works correctly. But my question is, if reloading manually without all that code works, that is, it appears and disappears, how can I make it appear and disappear without using the timers.

Thank you very much in advance.

Excuse my English I’m using google translator