Search code examples
javascriptjquerytime-wait

jQuery Set wait time before a function executes


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");
    }
}

Solution

  • You can use setTimeout:

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