0

I have some DOM elements, like this

<div class='parent'>
  <div>1</div>
  <div>2</div>
</div>

How I can track event, when 'parent' div has changed? As example I'm add <div>3</div> programmatically, with append(), or i'm drag div3 to 'parent' div.

  • 1
    Possible duplicate of [Detect changes in the DOM](http://stackoverflow.com/questions/3219758/detect-changes-in-the-dom) – Mohammad Sep 19 '16 at 12:22
  • try this one - $('.myClass').on('DOMNodeInsertedIntoDocument', function() { alert('myClass was inserted into the DOM'); } – Chetan Sep 19 '16 at 12:22

2 Answers2

1
<div class='parent'>
    <div>1</div>
    <div>2</div>
</div>
<button id="add">Add to Div</button>
$(".parent").bind("DOMSubtreeModified", function() {
    alert("div added");
});
$("#add").click(function() {
    $(".parent").append("<div>3</div>");
});
0

try this:

$('.parent').on("DOMNodeInserted", function(){
  //your code
});
Bartłomiej Gładys
  • 4,525
  • 1
  • 14
  • 24
  • According to this [question](http://stackoverflow.com/questions/6659662/why-is-the-domsubtreemodified-event-deprecated-in-dom-level-3), `DOMSubtreeModified` is deprecated. – Mohammad Sep 19 '16 at 12:24