I have a button on the html page, when user clicks on it part of the html form should be cloned and processed in certain way. Cloning and processing takes some time and I would like to display loader.
$(".dashed_button.add_supplier").click(function(){
$(".supply-details-tab .inner_tab .supplier_info_link").last().after('<div class="loader"></div>');
//Create new tab link
var newTabLink = $(".inner_tab .supplier_info_link").last().clone();
$(".inner_tab .supplier_info_link").removeClass("active");
$(newTabLink).addClass("active");
//Get last existing index
var lastIndex= parseInt($(newTabLink).attr('id').substring(14));
var newIndex = lastIndex+1;
var lastExistingTab = $(".supply-details-tab .tab-pane").last().find("> .subform_fields_wrapper");
cloningSupplyDetails($(lastExistingTab), $("#supplier_"+newIndex));
$(".supply-details-tab .inner_tab .loader").remove();
});
The problem is that after click button is frozen, no loader is displayed and the user cannot understand what is happening. After some time new cloned subform is displayed.
How can I stop the button from freezing and display a loader during function execution?