How to display a loader while processing a javascript function?

Posted on

Question :

I have a radio button that when clicked, performs a function that mounts a datepicker.

However, the mountDatepicker function only loads after a few seconds, after querying the three apis to mount the calendar.

So how do I load an image with a loader in place of the calendar while the function does not finish?

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




Answer :

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 this in a different way: as I suggest, or already having a div that overlaps the HTML in the calendar.

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

Example: link


Leave a Reply

Your email address will not be published. Required fields are marked *