How to show a loader while processing a javascript function?


I have a radio button that when clicked, executes a function that assembles a datepicker.

However, the mountDatepicker function is only loaded after a few seconds, after consulting three apis and then mounting the calendar.

So how do I load an image with a loader in place of the calendar while the function doesn't finish?

    if ($("input[name='diasaluguel']:checked").length > 0 ) {




function addLoader(el) {
    var gif = '';
    var img = document.createElement('img');
    img.src = gif;
    el.innerHTML = '';

Create a function to be run before mountDatepicker(); be called. You can do it differently: as I suggest, or already having a div in the HTML that overlaps the calendar.

As I did it adds an img element to the calendar and then removes it.


Scroll to Top