خرید بک لینک

Vote count: 0

I am having a problem with determining why a class is not being removed in an each function. I want to check and see if the element containing a specific class is being manipulated somehow by some other event or function.

This code is not succeeding in removing the class 'cc-gone' from the content elements.

var content = form.find('.cc-form-content-container');

$(content).each(function() {
  console.log('unhiding content containers');
  $(this).removeClass('cc-gone');      
});

I tried adding a MutationObserver, copying the demo, with slight modifications (the class name to track and the console output):

// select the target node
var target = document.querySelector('.cc-form-content-container');

// create an observer instance
var observer = new MutationObserver(function(mutations) {
  mutations.forEach(function(mutation) {
    console.log('mutation: '+mutation.type);
  });
});

// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true };

// pass in the target node, as well as the observer options
observer.observe(target, config);

// later, you can stop observing
observer.discoect();

However the console does not have any output matching the mutations.forEach, and I tested it by adding a $(this).addClass('x') in the each loop, and checked in the console that the class was added to the element.

Hopefully someone in the SO community can help point out either the right way to use MutationObserver to solve my problem or another way to find out why the 'cc-gone' class is not being removed from the element with the 'cc-form-content-container' class.

Any help is appreciated!

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 1 خرداد 1395 ساعت: 4:24

صفحه بندی