Edit in JSFiddle

function poll(fn, timeout, interval) {
    var endTime = Number(new Date()) + (timeout || 2000);
    interval = interval || 100;

    var checkCondition = function(resolve, reject) {
        // If the condition is met, we're done! 
        var result = fn();
        if(result) {
            resolve(result);
        }
        // If the condition isn't met but the timeout hasn't elapsed, go again
        else if (Number(new Date()) < endTime) {
            setTimeout(checkCondition, interval, resolve, reject);
        }
        // Didn't match and too much time, reject!
        else {
            reject(new Error('timed out for ' + fn + ': ' + arguments));
        }
    };

    return new Promise(checkCondition);
}

// Test
poll(function(){
  var html = document.getElementById("pollingDiv").innerHTML;
  if(html.search("NOW CHANGED") > -1){
    return true;
  }else{
    return false;
  }
}, 20000, 1000).then(function(){
  console.log("poll() function triggered");
}).catch(function(){
  console.log("poll() function failed");
});
setTimeout(function(){
  document.getElementById("pollingDiv").innerHTML = document.getElementById("pollingDiv").innerHTML + " [innerHTML NOW CHANGED]";
}, 10000);








<html>
<body>
  <div id="pollingDiv">
  The poll() function will fire when the innerHTML of this div changes after 10 seconds. Check the console.
  </div>
</body>
</html> 
body {
  font-family: arial;
}