Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <ol contenteditable oninput="">
    <li>Press enter and look at the console</li>
  </ol>
</body>
</html>
 
  var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var list = document.querySelector('ol');
var Observer = new MutationObserver(function(mutations){
  mutations.forEach(function(mutation){
    console.log(mutation.type);
  });
});
Observer.observe(list, {attributes:true});                    //只观察目标节点的属性节点
list.setAttribute("foo","bar");        //不管foo属性存在不存在,都会触发回调函数
list.setAttribute("foo","bar");        //即使前后两次的属性值一样,还是会触发回调函数
list.removeAttribute("foo");            //移除foo属性节点,触发回调函数
list.removeAttribute("foo");            //不会触发回调函数,因为已经没有属性节点可移除了
Observer.observe(list, {attributes:true,attributeFilter:["bar"]});     
   //指定要观察的属性名
list.setAttribute("foo","bar");        //不会触发回调函数,因为attributeFilter数组不包含"foo"
list.setAttribute("bar","foo"); 
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
andypinetpro
0viewers