0

Is there any kind of event listener in javascript which checks if any new child node is added to the target node? If not, is there any way to keep track of a particular node to check if a new child Node is added to it

To Make my question more comprehensive I'll use a small example, So consider,

 <ul>
  <li></li>
  <li></li>
 </ul>

So in the above context can we add an eventListener to ul Node to check if a new li node is added to it(dynamically via js) ?

  • 1
    [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) – 0stone0 Jun 16 '21 at 15:04
  • I could not understand the callback() {Callback function to execute when mutations are observed} of MutationObserver(), I mean the parameter of the callback is a bit confusing the function body too is confusing could you please explain it to me – Uchiha Itachi Jun 16 '21 at 15:14
  • 1
    The [third answer](https://stackoverflow.com/a/45271114/5625547) gives an example using `MutationObserver`. – 0stone0 Jun 16 '21 at 15:17
  • 1
    Yeah, I read the answer and could understand it partiallly. I'll read some more blogs and would understand it maybe. Thanks for the help @0stone0 – Uchiha Itachi Jun 16 '21 at 15:40

0 Answers0