Mehul Prajapati

Mehul Prajapati

  • NA
  • 1.3k
  • 44.3k

Wait until another thread is working in jQuery

Jan 2 2018 12:38 AM
Here, I am waiting for html button element from the popup iframe window. When a popup is open then my block of code will fire the click event on time and it's working fine, but my query is wanting to wait until not get button.
 
I have used the nested function calling with timeout thread, so when I call then work, but don't wait and go to the next task.
  1. setPrint();   
  2. function setPrint() {   
  3.    setTimeout(function () {   
  4.       var btnprint = null;   
  5.       var frame = $('#WindowFadeiFrame').get(0).contentDocument;   
  6.       var btn = $('#btn', frame);   
  7.       if (btn.length == 0) {   
  8.          btnprint == null   
  9.          console.log('not found');   
  10.       }   
  11.       else {   
  12.          btn.click();   
  13.          btnprint = btn;   
  14.          console.log('found now');   
  15.       }   
  16.       if (btnprint == null) {  
  17.          setPrint(); }   
  18.    }, 100);   
  19. }

Answers (3)