Тема: MutationObserver
Показать сообщение отдельно
  #7 (permalink)  
Старый 15.02.2013, 20:36
Кандидат Javascript-наук
Отправить личное сообщение для Bebarr Swallow Посмотреть профиль Найти все сообщения от Bebarr Swallow
 
Регистрация: 17.03.2011
Сообщений: 113

Mozilla Firefox тупо записал насмерть.. xD

Писал так:
// select the target node
var target = document.querySelector('.img'); // сейчас я понял что нужно указать body
 
// create an observer instance
var observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
        if(/img/.test(mutation.target.className)) // как тогда отлавливать новые .img?
          mutation.target.style.outline = "1px solid red"
    });    
});

// 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.disconnect();
Ответить с цитированием