2017-10-22 12 views
0

私の理解からmutationObserverは、eventListenersと同様に使用されます。私はイベントリスナーの代わりにそれを使用しようとしているので、divに変更に反応させることができます。私の問題は、divに何かを入力したときにコンソールに何も印刷されていないことです。コンソールには何かが印刷されるべきですが、そうではありませんし、理由もわかりません。私はここで間違って何をしていますか?なぜmutationObserverは機能しませんか?

<div contenteditable="true" class="input"></div> 
    <div class="display"></div> 


     let input= document.getElementsByClassName("input")[0]; 
     let displat= document.getElementsByClassName("dispaly")[0]; 

     let config={attributes:true, childlist:true, characterData:true}; 

     let observer= new MutationObserver(function(mutations){ 
      mutations.forEach(function(mutation){ 
      console.log(mutation.type); 
      }); 
      }); 
    observer.observe(input,config);  

答えて

0

"childlist"と書いてありますが、Lを大文字にして "childList"である必要があります。

+1

..oh okありがとう! – user0897345

関連する問題