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 🙏

© 2025 – Pkg Stats / Ryan Hefner

jquery-onmutate

v1.4.2

Published

A MutationObserver wrapper for jQuery, allowing you to listen for element creation, attribute modification, and text changes.

Readme

jQuery-onMutate

This plugin is a wrapper for the MutationObserver class, with a fallback to setInterval, so you can execute code when elements matching a given selector are created or have their attributes or text changed. It includes three methods: .onCreate(), .onModify(), .onText(), and .onMutate().

This plugin is dependent on jQuery (tested on version 1.6.4)

Installation

npm install --save jquery-onmutate

Usage

var onMutate = require('jquery-onmutate');
var jQuery = require('jquery');

onMutate(jQuery);

API

.onCreate()

Attaches a listener to an existing parent element, and executes a callback when a new descendent element matching a given selector is created. If a matching element already exists, the callback will execute immediately.

parent.onCreate(selector, callback[, multi = false]);

parent (jQuery) a single parent element that is a known ancestor of the created element(s). Only the first element in the set will be used.

selector (string) is a valid jQuery selector for the new element(s). OnMutate will poll for a valid new element using jQuery(selector, parent)

callback (function) the callback executed when a new matching element is created. It receives one argument, elements, which is a jQuery object containing the new elements.

multi (boolean) determines whether the observer will continue to poll for new elements after a match is found. If false, the observer will shut itself off after the first match(es); this includes if matching elements already exist when onCreate is called. Otherwise, it will continue to poll, but will only operate on each created element once.

$.onCreate() will attach the onCreate listener to the document, i.e. is the same as $(document).onCreate().

parent.onCreate('detach');

This usage shuts off the onCreate listener.

.onModify()

Attaches a listener to a single element, and executes a callback whenever one of its attributes is changed with optional conditions. While the callback executes the listener will be momentarily shut off, to prevent infinite loops if the callback also changes the element's attributes.

element.onModify([attributes[, match,]] callback[, multi = false]);

element (jQuery) the element to be observed.

attributes (string) is a space-separated list of attributes to watch. If omitted, the callback will execute on any attribute change.

match (string|RegExp) is a string or RegExp that will be matched against the new value of any modified attribute(s). If you set a match then you must also specify the attributes to watch.

callback (function) is the function to execute when a qualifying change is made to the element's attributes. It receives one argument, element, which is a jQuery object containing the affected element.

multi (boolean) determines whether the observer will continue to poll for changes after the callback executes. If false, the observer will shut itself off after the first qualifying change; otherwise, it will continue to poll.

element.onModify('detach');

This usage shuts off the onModify listener.

.onText()

Attaches a listener to a single element, and executes a callback whenever its text content changes with optional conditions. While the callback executes the listener will be momentarily shut off, to prevent infinite loops if the callback also changes the element's text.

element.onText([match,] callback[, multi = false])

element (jQuery) is the element to be observed.

match (string|RegExp) is an optional string or RegExp that will be matched against element's new text content, as read with jQuery's .text() method.

callback (function) is the function to execute when a qualifying change is made to the element's text content. It receives one argument, element, which is a jQuery object containing the affected element.

multi (boolean) determines whether the observer will continue to poll changes after the callback executes. If false, the observer will shut itself off after the first qualifying change; otherwise, it will continue to poll.

element.onText('detach');

This usage shuts off the onText listener.

.onMutate()

An alternative way to call one of the methods above, passing the type of mutation as an argument.

element.onMutate(type, ...)

element (jQuery) is the element to be observed.

type (string) should be "create", "modify", or "text".

Additional arguments are specific to the method being invoked.

Additional Notes:

  • .onCreate() internally creates a MutationObserver that observes with the childList and subtree options.
  • .onModify() internally creates a MutationObserver that observes with the attributes option.
  • .onText() internally creates a MutationObserver that observes with the characterData, childList, and subtree options. This is so it can recognize text node insertion and deletion as a text change, as well as observing characterData changes to existing text nodes.
  • For browsers that do not support MutationObserver, this plugin will check all observed elements at 50ms intervals for changes that match the conditions. Because of this, there can be a slight delay/flash before the callback executes for these browsers.