0

Looking to change from using DOMSubtreeModified to mutation observer in a non-jQuery script.

Current code to process document links looks like:

document.addEventListener("DOMSubtreeModified", transform, false);

function transform(e) {
    if (element.nodeName.toLowerCase() == "a") {
        processLink(element);
    }
    if (element.getElementsByTagName) {
        var a = element.getElementsByTagName("a");
        for (var i = a.length; i--; i > 0) {
            processLink(a[i]);
        }
    }
}

Found code here, but it uses jQuery and am not sure about what goes in the do something part. Tried reading other docs on Mutation Observers but didn't get very far.

Craig S. Anderson
  • 6,966
  • 4
  • 33
  • 46
  • 1
    Check my answer here: https://stackoverflow.com/questions/40383461/detect-changes-in-dom-elements-order/40383782#40383782 there is a good example there. I know there is jquery in the answer, but it's not related to the MutationObserver part – Dekel Aug 24 '17 at 00:06
  • Does it help? Let me know – Dekel Aug 24 '17 at 00:26
  • @Dekel - It helps, thanks. Need to figure out the right target and the "// You can check the actual changes here" part. – Craig S. Anderson Aug 24 '17 at 00:48

0 Answers0