You can use MutationObserver
. I wrote an example here :
http://jsbin.com/vahixehema/edit?html,js,output
var target = document.getElementById('foo');
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName === "class") {
// the class of the target node changed
if(!target.className.match(/\bbar\b/)){
// bar is now not present
alert("class 'bar' was removed");
observer.disconnect();
// reload the page here.
}
}
});
});
observer.observe(target, { attributes: true });
// remove class after 3 seconds
window.setInterval(function(){
target.classList.remove("bar");
}, 3000);
The basic idea is to listen for when the class
attribute of your target node changes, and then when it does, check if the class you care about has been removed.
If you're using jQuery
anyway, you could probably use !$.hasClass('bar')
or something like that instead to check if the class has been removed.