Answers for "js listen for class change event"

0

js listen for class change event

const btn = document.querySelector('.btn')
const options = {
  attributes: true
}

function callback(mutationList, observer) {
  mutationList.forEach(function(mutation) {
    if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
      // handle class change
    }
  })
}

const observer = new MutationObserver(callback)
observer.observe(btn, options)
Posted by: Guest on May-02-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language