-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,21 @@ | ||
# wait-for-it.js | ||
A JavaScript Library that allows you to execute function when a certain element gets added to the document | ||
|
||
## Getting Started | ||
|
||
If you want to use the latest version you can use jsDelivr CDN to import `wait-for-it.js` into your application as follows: | ||
|
||
```html | ||
<script src="https://cdn.jsdelivr.net/gh/cstayyab/wait-for-it.js@main/wait-for-it.js"></script> | ||
``` | ||
|
||
Then you can just call `waitForElement` function with `selector` and a `callback` to see the [magic](#working). | ||
|
||
It's just simple as that. | ||
|
||
|
||
## Working | ||
|
||
`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. |