dom-change-event
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

dom-change-event

NPM version Downloads
Detect all changes in the DOM (added elements, removed elements, attributes updates)

Installation

npm i dom-change-event

Usage

import DomChangeEvent from 'dom-change-event';
DomChangeEvent(); // init the listener

// you can add these listeners for all HTML elements
document.body.addEventListener("addedNodes", (e) => {
    console.log("addedNodes in body element", e.detail);
});

document.body.addEventListener("removedNodes", (e) => {
    console.log("removedNodes in body element", e.detail);
});

const div = document.createElement("div");
document.body.append(div);
div.addEventListener("attributeChange", (e) => {
    console.log("attributeChange", e.detail);
    console.log("attributeName", e.detail.attributeName);

    console.log("attributeOldValue", e.detail.oldValue);
    const htmlElement = e.detail.target;
    console.log("attributeNewValue", htmlElement.getAttribute(e.detail.attributeName));
});
div.setAttribute("myAttribute", "myValue");

setTimeout(() => {
    div.remove();
}, 2000);

Events list

Event Description Value
addedNodes Get array of elements added in an HTMLElement Array[HTMLElement]
removedNodes Get array of elements removed from an HTMLElement Array[HTMLElement]
attributeChange Get attribute change information from an HTMLElement attributeName: The name of the attribute
oldValue: The old value attribute
target: the HTMLElement

Package Sidebar

Install

npm i dom-change-event

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

12.5 kB

Total Files

9

Last publish

Collaborators

  • dani-404