My code is the following. When I click the search button, it enters a for loop that prints 5000 times "hi". Before this calculation begins, I want to disable the button. After the console.log is finished, I want to reenable this button. But for some reason, this isn't working. (To be more precise, although here I am simply printing logs, my actually work involves various calculations that take around 5 seconds to finish using for loops.)
$("#search").click(function() {
   $("#search").prop("disabled",true);
   $("#search").text("Loading...");
   var i;
   for(i = 0; i < 50000; i++)
       console.log("hi");
   $("#search").prop("disabled",false);
   $("#search").text("Finished...");
});
 
     
     
    