Skip to content

Commit

Permalink
Added README
Browse files Browse the repository at this point in the history
  • Loading branch information
cstayyab authored May 6, 2021
1 parent 57ee795 commit 86d3f9f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
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.

0 comments on commit 86d3f9f

Please sign in to comment.