Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Latest commit

 

History

History
49 lines (35 loc) · 1.14 KB

attrchangecallback.md

File metadata and controls

49 lines (35 loc) · 1.14 KB

DOM/attrChangeCallback()

This function observes changes on attributes of the given element.

Import

import attrChangeCallback from '@web-native-js/play-ui/src/dom/attrChangeCallback.js';

Syntax

attrChangeCallback(el, callback[, filter = []]);

Parameters

  • el - HTMLElement: The specific element to observe.
  • callback - Function: The callback function that recieves the notification. This callback will be called once for every change with the following arguments.
    • mutation - MutationEntry: An object representing the mutation that occured.
  • filter - Array: (Optional) A more specific list of attributes to observe.

Return

  • MutationObserver - The instantiated MutationObserver.

Usage

<body>
  <div id="el1" class="cls1"></div>
</body>
// Obtain an element instance
let el1 = document.querySelector('#el1');

// Observe
attrChangeCallback(el1, mutation => {
    console.log('The class attribute has changed.', mutation);
});

// Start mutating
setTimeout(() => {
    el1.classList.add('cls2'); // The class attribute has changed.
}, 1000);