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

@afixt/vanilla-live-regions

v1.0.1

Published

Vanilla JavaScript library for managing ARIA live regions

Readme

Vanilla Live Regions

A modern, vanilla JavaScript library for managing ARIA live regions on web pages. This library provides an easy-to-use API for creating and managing live regions that announce content changes to screen reader users.

Features

  • 🚀 Zero dependencies - pure vanilla JavaScript
  • 📦 Small footprint - lightweight and efficient
  • 🎯 Modern ES6+ syntax with backward compatibility
  • 🔧 Flexible API - works with selectors, elements, or NodeLists
  • ♿ Full ARIA support with sensible defaults
  • 🧪 Thoroughly tested with modern testing tools

Getting Started

Installation

Install via npm:

npm install vanilla-live-regions --save

Or include directly in your HTML:

<script type="module">
  import LiveRegion from './dist/liveRegion.mjs';
</script>

Usage

Basic Usage

import LiveRegion from 'vanilla-live-regions';

// Create a live region with default settings
const element = document.getElementById('my-region');
LiveRegion(element);

Using CSS Selectors

// Apply to single element
LiveRegion('#status-message');

// Apply to multiple elements
LiveRegion('.notification');

Custom Configuration

LiveRegion('#news-ticker', {
  label: 'News Updates',
  role: 'status',
  live: 'polite',
  atomic: 'true'
});

Creating Dynamic Live Regions

// Create a new live region dynamically
const alertRegion = LiveRegion.create({
  role: 'alert',
  label: 'System Alerts'
});

// Update its content
LiveRegion(alertRegion, {
  text: 'New notification received!',
  replace: true
});

API Reference

LiveRegion(selector, options)

Creates or updates a live region.

Parameters

  • selector - Can be:

    • CSS selector string (e.g., '#my-element', '.my-class')
    • HTMLElement
    • NodeList
    • Array of HTMLElements
  • options - Configuration object with the following properties:

| Property | Type | Default | Description | |----------|------|---------|-------------| | labelledby | string | null | ID of element to use as label (aria-labelledby) | | label | string | null | Text label for the region (aria-label) | | role | string | 'region' | ARIA role (region, status, alert, log, marquee, timer, progressbar) | | atomic | string | 'false' | Whether to announce entire region or just changes | | live | string | 'polite' | Announcement priority (polite, assertive) | | relevant | string | 'additions' | What changes to announce (additions, removals, text, all) | | busy | string | 'false' | Whether region is being updated | | className | string | undefined | CSS class to add to the element | | replace | boolean | false | Whether to replace existing content | | text | string | undefined | Content to add/replace in the region | | wait | number | 200 | Delay (ms) before updating content |

Static Methods

LiveRegion.create(options)

Creates a new live region element and appends it to the document body.

const notification = LiveRegion.create({
  role: 'status',
  label: 'Notifications'
});

LiveRegion.findAll()

Returns all elements on the page that have live region attributes.

const allRegions = LiveRegion.findAll();
console.log(`Found ${allRegions.length} live regions`);

LiveRegion.remove(selector)

Removes all live region attributes from the specified element(s).

LiveRegion.remove('#my-region');

Common Use Cases

Status Messages

LiveRegion('#status', {
  role: 'status',
  text: 'Form saved successfully',
  replace: true
});

Error Alerts

LiveRegion('#errors', {
  role: 'alert',
  text: 'Error: Invalid email address',
  replace: true
});

Progress Indicators

const progressRegion = LiveRegion('#progress', {
  role: 'progressbar',
  label: 'Upload Progress',
  busy: 'true'
});

// Update progress
LiveRegion(progressRegion, {
  text: 'Upload 45% complete',
  replace: true
});

// Complete
LiveRegion(progressRegion, {
  text: 'Upload complete',
  busy: 'false',
  replace: true
});

Chat or Activity Logs

LiveRegion('#chat-log', {
  role: 'log',
  label: 'Chat Messages',
  relevant: 'additions text'
});

// Add new messages
LiveRegion('#chat-log', {
  text: '<div>User: Hello!</div>',
  replace: false  // Append, don't replace
});

Development

Setup

# Install dependencies
npm install

# Run development server
npm run dev

# Build for production
npm run build

# Run tests
npm test

# Run tests with UI
npm run test:ui

# Check coverage
npm run test:coverage

Project Structure

├── src/
│   └── liveRegion.vanilla.js    # Main library source
├── test/
│   └── liveRegion.test.js       # Test suite
├── dist/                         # Built files (generated)
├── demo.html                     # Interactive demo
└── vite.config.js               # Build configuration

Browser Support

This library supports all modern browsers and provides fallbacks for older browsers that support ES5.

Migration from jQuery Version

If you're migrating from the jQuery version:

  1. Remove jQuery dependency

  2. Update your imports:

    // Old
    $('#element').liveRegion(options);
       
    // New
    import LiveRegion from 'vanilla-live-regions';
    LiveRegion('#element', options);
  3. The API remains largely the same, with the main difference being the function call syntax.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details

More Information

For more information about ARIA live regions: