Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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)
Source by nikitahl.com #
 
PREVIOUS NEXT
Tagged: #js #listen #class #change #event
ADD COMMENT
Topic
Name
9+9 =