jQuery Set wait time before a function executes

HaBo picture HaBo · Apr 25, 2012 · Viewed 19.7k times · Source

How can i set wait time for this function.

function UpdateMedicaitonHistory(data) {
     MedicaitonHistoryGrid();
//set a wait time to finish MedicaitonHistoryGrid() like for 3 seconds
// then execute the below code.
if ($("#MedHistoryGridSec").is(":visible")) {
            alert("yes we have grid");
      }
else{
     alert("No Grid");
    }
}

Answer

Tejs picture Tejs · Apr 25, 2012

You can use setTimeout:

setTimeout(function()
{
     if($('#MedHistoryGridSec').is(':visible'))
         alert('yes');
     else
         alert('no');
}, 3000);