Answers for "javascript event listener change class"

2

when classes change event listener js

const mutationObserver = new MutationObserver(mutationsList => {
      mutationsList.forEach(mutation => {
		if (mutation.attributeName === 'class') {
			// classes have changed
		}
	});
});

mutationObserver.observe(
	// a document object you want to watch. some examples of document objects:
	// document.getElementById('id')
	// document.getElementsByClassName('class')[5]
	// document.querySelector('[query=selector]')
	// etc
	,{ attributes: true }
)

// when you wanr to remove the listener
mutationObserver.disconnect();
Posted by: Guest on January-25-2021

Code answers related to "javascript event listener change class"

Code answers related to "Javascript"

Browse Popular Code Answers by Language