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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@alexspirgel/children-loaded

v1.0.1

Published

A JavaScript function for determining if child elements are loaded.

Readme

Children Loaded

Children Loaded is a JavaScript function for determining if child elements are loaded. This script was developed for use with built-in web components, but it is flexible enough to be used in other contexts as well.

The Built-In Web Component Problem

Built-in web components are HTML elements that can behave as a registered custom element. You can read more about built-in web components here: https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements

A problem occurs when a built-in custom element is constructed and need access to its child elements. Available native callbacks fire too early. Both the constructor and the connectedCallback methods are called before child elements are parsed. You can read a lengthy discussion about this issue here: https://github.com/WICG/webcomponents/issues/809

Installation

Option 1: Install using NPM

Install the script using NPM via the command line:

npm install @alexspirgel/children-loaded

Require the script in the codebase where necessary:

const childrenLoaded = require('@alexspirgel/children-loaded');

Option 2: Install using a script tag

Download the normal or minified script from the 'dist' folder.

Add a script tag with a path to the downloaded file. Make sure this script tag is placed before other script tags that need access to the childrenLoaded function.

<script src="path/to/children-loaded.min.js"></script>

Usage

const childrenLoaded = require('@alexspirgel/children-loaded');

class MyCustomElement extends HTMLUListElement {
	constructor() {
		super();
		this.querySelectorAll('li'); // returns 0 nodes
	}
	async connectedCallback() {
		this.querySelectorAll('li'); // returns 0 nodes
		await childrenLoaded(this);
		this.querySelectorAll('li'); // returns 3 nodes
	}
}

customElements.define('my-custom-element', MyCustomElement, {extends: 'ul'});
<ul is="my-custom-element">
	<li>item 1</li>
	<li>item 2</li>
	<li>item 3</li>
</ul>

View a working demo →

Alternative solutions

Extend native element with custom callback

Another way to address this problem is to extend a native element class with a custom callback. The underlying logic of the callback would be similar to that of the children loaded script, but instead of a separate function it would be an available callback method on the element class, similar to connectedCallback. In my opinion this approach constrains the versatility available to built-in web components, their ability to extend many native elements. With this approach you could either use one base element class or create custom versions of all extendable native elements. The html-parsed-element repository (https://github.com/WebReflection/html-parsed-element) takes the base element class approach meaning you are able to use this repository for all elements that implement the HTMLElement class. This includes many elements, but not all. Some notable omissions are: <a>, <button>, <div>, and many more.

Wait for the entire page to load

This is commonly accomplished with callbacks such as the vanilla DOMContentLoaded document event listener or the jQuery $('document').ready function. Both of these solutions are sufficient, but they wait for the entire document to be loaded. The childrenLoaded function can be used to initialize these scripts as soon as only the minimum required elements for that script are loaded. This could be especially impactful for components that affect interactable content at the immediately visible section of a large webpage.