0

I've been browsing several threads about this, this one: http://stackoverflow.com/a/24284069/663246 works perfectly when some class changes, but I need something more specific:

If class1 is added to class2, do something.

If class2 is removed, do something (go back).

Do I need to specify this on the observer or can I do it on the function?

Thank you in advance,

EDIT:

Thanks, that sounds good, but sorry I'm a little bit lost here. Here it is what I've got so far:

$(function() {
(function($) {
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;

    $.fn.attrchange = function(callback) {
        if (MutationObserver) {
            var options = {
                subtree: false,
                attributes: true,
                attributeOldValue: true,
                attributeFilter: ['class']
            };

            var observer = new MutationObserver(function(mutations) {
                mutations.forEach(function(e) {
                    callback.call(e.target, e.attributeOldValue);
                });
            });

            return this.each(function() {
                observer.observe(this, options);
            });

        }
    }
})(jQuery);

$('.white-text').attrchange(function(attrName) {

    if(attrName=='class'){
        $("#about").css( "color", "white" );
    }else{
        $("#about").css( "color", "black" );
    }

});
});

I need to change the color of #about if class .active is added to .white-text

Juárez
  • 121
  • 1
  • 1
  • 10

0 Answers0