DOMSubtreeModified not working in chrome

情到浓时终转凉″ 提交于 2019-12-12 13:05:14

问题


I have this code working perfectly in firefox.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
    function CreateEvent()
      {
      var x = document.createEvent("MutationEvent");
      x.initMutationEvent("DOMSubtreeModified", true, false, null, "", "", "", 0);
      document.dispatchEvent(x);
      }
    $(document).ready(function() {

        $('#myDiv')[0].addEventListener('DOMNodeRemoved', function () { console.log('Content removed!'); }, false);
        $('#myDiv')[0].addEventListener('DOMSubtreeModified', function () { console.log('DOMSubtreeModified modified!'); },  false);
        $('#myDiv')[0].addEventListener('DOMNodeRemovedFromDocument', function () { console.log('DOMNodeRemovedFromDocument !'); },  false);
        $('#myDiv')[0].addEventListener('DOMNodeInserted', function () { console.log('DOMNodeInserted !'); },  false);

        $('#myBtn').click(function (e) {

            $('#myDiv').css({ marginLeft : "300px"});
        });
    });

</script>
</head>
<body>
<div id="myDiv">Content</div>
<div id="myBtn">
    Button
</div>
</body>
</html>

But it's not working on Chrome. I want an event triggered everytime something happens to myDiv. (remove, css modifcation, everything).

Any work-arounds?


回答1:


It won't work going forward. DOM mutation events have been deprecated and won't be supported going forward, http://www.w3.org/TR/DOM-Level-3-Events/#events-mutationevents.



来源:https://stackoverflow.com/questions/7837510/domsubtreemodified-not-working-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!