Skip to content

Commit

Permalink
Added Timeout Example
Browse files Browse the repository at this point in the history
  • Loading branch information
cstayyab committed May 9, 2021
1 parent 92ba9b6 commit a7a80b6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ It's just simple as that.
`wait-for-it.js` uses HTML [`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) to wait for the selectors registered to it. Whenever an element gets added to the document, if checks for the registered selectors and if it finds an element with that selector it executes your `callback` function and removes that `callback` from its queue to prevent retriggering.

And that is how the magic happens.

## Update v0.1.1:
Now you can specify a third parameter `timeout` to `waitForElement`. If the specific element does not appear in the given time your callback will be called with a `timeout` = `true` instead and the `selector` will also be removed from the queue. Here is an example:

```javascript
waitForElement('#NonExistentSelector', function (timeout) {
if(timeout === true) {
console.log('As Expected, Element with #NonExistentSelector did not appear in 1000 milliseconds.');
return;
}
console.log('This is not possible at all!');
}, 1000);
```

0 comments on commit a7a80b6

Please sign in to comment.