Detect when an element matching an ID is loaded into the DOM.
import elementLoadedById from 'element-loaded-by-id';
elementLoadedById(id).then(element => {
// Do something...
});
npm i element-loaded-by-id
See example.
elementLoadedById(id)
id
: A unique ID for the element.
A Promise
that is:
- Already fulfilled, if the element is found already loaded into the document.
- Already rejected, if the element was not found and the DOM has already finished loading.
- Asynchronously fulfilled, when a mutation occurs that adds the element into the DOM.
- Asynchronously rejected, when the DOM has finished loading and the element has not been found.
elementLoadedById()
will search the document for the element by ID.
It will continue searching until the DOM has finished loading (DOMContentLoaded
event).
See also: