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

Overview

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:

<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.

It's just simple as that.

Working

wait-for-it.js uses HTML 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:

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);
You might also like...

Awesome-book is an online library website where a user can store a collection of books. Different book can be added and removed. Built with JavaScript using Dom

Awesome-book Description Awesome-book is an online library website where a user can store a collection of books. Differents book can be added and remo

Sep 9, 2022

A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM deffiniation and appropriate file structure.

Welcome to function-stencil 👋 A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM

Jun 20, 2022

Wrap a function with bun-livereload to automatically reload any imports inside the function the next time it is called

bun-livereload Wrap a function with bun-livereload to automatically reload any imports inside the function the next time it is called. import liveRelo

Dec 19, 2022

SEE WHO GETS TO A SCORE OF A 100 FIRST

SEE WHO GETS TO A SCORE OF A 100 FIRST

PIG-GAME RULES 1 . The main goal is to reach a score equal or above to a 100. 2 . To play, click on the button named " ROLL DICE ". 3 . To hold your s

Jun 12, 2021

Sorting Arrays as simple as it gets.

Sort Sorting Arrays as simple as it gets. This module is published at: https://deno.land/x/sort. Simple Usage Example import { SortService, Direction

May 12, 2022

Gets news from liveuamap.com and sends it to a Discord webhook

Gets news from liveuamap.com and sends it to a Discord webhook

Jun 27, 2022

Gets system requirement information to compare to the ones shown in Steam.

Steam SysReq Gets system requirement information to compare to the ones shown in Steam. Usage import getSteamSysReq from 'steam-sysreq'; const steamS

Nov 15, 2022

Chrome Extension - Gets your Trybe Agenda from slack

Chrome Extension - Gets your Trybe Agenda from slack

Trybe Schedule Notification Extensão para navegadores base chromium para facilitar o dia a dia do estudante da Trybe. Sumário Instalação Uso FAQ Contr

Apr 8, 2022

"To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark them as complete. You will build a simple website that allows for doing that, and you will do it using ES6 and Webpack!

To-do-list Description "To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark t

Oct 18, 2022
Releases(0.1.1)
Owner
Muhammad Tayyab Sheikh
Software Engineer @ Envoy Innovations (https://envoymobile.com)
Muhammad Tayyab Sheikh
The world's fastest game! User gets ten dice. Then rolls and rolls as fast as they can until he gets all their dice on the same number.

tenzies-game The world's fastest game! User gets ten dice. Then rolls and rolls as fast as they can until he gets all their dice on the same number. I

Babur Shah Sayer 6 Nov 26, 2022
Tries to execute sync/async function, returns a specified default value if the function throws

good-try Tries to execute sync/async function, returns a specified default value if the function throws. Why Why not nice-try with it's 70+ million do

Antonio Stoilkov 14 Dec 8, 2022
Esther Udondian 6 Aug 1, 2022
JavaScript micro-library: pass in an element and a callback and this will trigger when you click anywhere other than the element

Add a click listener to fire a callback for everywhere on the window except your chosen element. Installation run npm install @lukeboyle/when-clicked-

Boyleing Point 5 May 13, 2021
This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do any operations that can be performed in python shell with this package.

Django execute code This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do

Shinu 5 Nov 12, 2022
Cryptostat is a Node.js based CLI that gets you the real-time stats of your favorite cryptocurrency.

Cryptostat-CLI Cryptostat is a Node.js based CLI that gets you the real-time stats of your favorite cryptocurrency. Installation Use the npm package m

Kunal Rohitas 5 Dec 15, 2022
An interactive app that allows adding, editing and removing tasks of a to-do list. Drag-and-drop featured added. Webpack was used to bundle all the Js modules in to one main Js file.

To-do List A to-do list app This app let you to set your own to-do list. Built With HTML CSS JavaScript WebPack Jest Live Page Page Link Getting Start

Kenny Salazar 7 May 5, 2022
The project is a To-Do list project to help plan daily, weekly or monthly activity. I used Html, CSS and JavaScript Technology to execute the project.

<<<<<<< HEAD To Do List This project is geared towards applying acguired skills for development of my porfolio through the following practices: Create

Victor Efosa Osagie 6 Dec 19, 2022
Awesome book website, small online library to store books when added to the list we have implemented this using a plaint JavaScript!

microverse-m2-Awesome-books This project is about building Awsome Books using javascript Live demo Live Demo Link Built With -Lighthouse (An open-sour

Oybek Kayumov 16 Dec 27, 2022