“Let me wait-for-it and call you back”, said wait-for-it.js

Ever encountered as situation where you had to wait for some HTML element in a webpage before you can execute a function?
Wait no more, because wait-for-it.js is at your service.

What does it offer?

It offers you a much simpler way to execut…


This content originally appeared on DEV Community and was authored by Muhammad Tayyab Sheikh

Ever encountered as situation where you had to wait for some HTML element in a webpage before you can execute a function?
Wait no more, because wait-for-it.js is at your service.

What does it offer?

It offers you a much simpler way to execute a function (callback) when your specified (selector) element gets added to the page.

## How does it work?
It uses nothing else but your very own JavaScript to accomplish the task i.e. JavaScript's MutationObserver API. You can have a detailed look at its code here:

GitHub logo cstayyab / wait-for-it.js

A JavaScript Library that allows you to execute function when a certain element gets added to the document

How do I use it?

Step 1: Include it in your webpage using jsDelivr CDN

<script src="https://cdn.jsdelivr.net/gh/cstayyab/wait-for-it.js@0.1.0/wait-for-it.js"></script>

Step 2: Register a selector to listen:

waitForElement('#food', function () {
    alert("Your Food is Here!");
});

Step 3: Voilà!!



Feel free to star and fork it on GitHub


This content originally appeared on DEV Community and was authored by Muhammad Tayyab Sheikh


Print Share Comment Cite Upload Translate Updates
APA

Muhammad Tayyab Sheikh | Sciencx (2021-05-07T00:26:09+00:00) “Let me wait-for-it and call you back”, said wait-for-it.js. Retrieved from https://www.scien.cx/2021/05/07/let-me-wait-for-it-and-call-you-back-said-wait-for-it-js/

MLA
" » “Let me wait-for-it and call you back”, said wait-for-it.js." Muhammad Tayyab Sheikh | Sciencx - Friday May 7, 2021, https://www.scien.cx/2021/05/07/let-me-wait-for-it-and-call-you-back-said-wait-for-it-js/
HARVARD
Muhammad Tayyab Sheikh | Sciencx Friday May 7, 2021 » “Let me wait-for-it and call you back”, said wait-for-it.js., viewed ,<https://www.scien.cx/2021/05/07/let-me-wait-for-it-and-call-you-back-said-wait-for-it-js/>
VANCOUVER
Muhammad Tayyab Sheikh | Sciencx - » “Let me wait-for-it and call you back”, said wait-for-it.js. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/07/let-me-wait-for-it-and-call-you-back-said-wait-for-it-js/
CHICAGO
" » “Let me wait-for-it and call you back”, said wait-for-it.js." Muhammad Tayyab Sheikh | Sciencx - Accessed . https://www.scien.cx/2021/05/07/let-me-wait-for-it-and-call-you-back-said-wait-for-it-js/
IEEE
" » “Let me wait-for-it and call you back”, said wait-for-it.js." Muhammad Tayyab Sheikh | Sciencx [Online]. Available: https://www.scien.cx/2021/05/07/let-me-wait-for-it-and-call-you-back-said-wait-for-it-js/. [Accessed: ]
rf:citation
» “Let me wait-for-it and call you back”, said wait-for-it.js | Muhammad Tayyab Sheikh | Sciencx | https://www.scien.cx/2021/05/07/let-me-wait-for-it-and-call-you-back-said-wait-for-it-js/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.