npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

element-loaded

v1.0.4

Published

Detect when an element matching a selector is loaded into the DOM using Promise and MutationObserver.

Downloads

10

Readme

elementLoaded()

Detect when an element matching a selector is loaded into the DOM.

Synopsis

elementLoaded(selector)
    .then((element) => {
        // ...
    });

Syntax

elementLoaded(selector)
elementLoaded(selector, target)

Parameters

selector: A selector to match against.

target (Optional): An element to query and observe for matches. By default, this is the entire document.

Return Value

A Promise that is:

  • Already fulfilled, if the selector matched an element already loaded into the document.
  • Already rejected, if no match was found and the DOM has already finished loading.
  • Asynchronously fulfilled, when a mutation occurs that adds an element matching the selector into the DOM.
  • Asynchronously rejected, when the DOM has finished loading and a matching element has not been found.

Description

elementLoaded() will search the document with querySelector() against a given selector. If there is a match, then the returned promise will resolve immediately. If there is no match, but the document readyState is no longer loading, then the returned promise will reject immediately.

Otherwise, it will observe the document for matches using MutationObserver. If a matching mutation is observed, then the promise will resolve. By the time that the DOM has finished loading and the DOMContentLoaded event is fired, if no matching element has been found, then the promise will reject and the observer will disconnect.

Alternatives are:

See also:

Examples

See examples.