0

I need to detect when div text is changed. I have multiple buttons which every one can change the text in the div. Unfortunately,the following code doesn't work. I also read that DOMSubtreeModified and Mutation area are deprecated and solutions in stackoverflow don't work for me.

(function($) { 

$('body').on('DOMSubtreeModified', '.heading-price', function(){
  console.log('changed');
});
})(jQuery);
Sobirjonovs
  • 18
  • 1
  • 4
matep05
  • 67
  • 7
  • Use a [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) – Rory McCrossan Jan 19 '21 at 13:40
  • .heading-price is a div with price. I have multiple buttons on site, every one is changing a price in above div. I need to detect when price is changing so i cant use click event. – matep05 Jan 19 '21 at 13:44
  • @DeepakDholiyan I think you're misunderstanding what's being asked. – Rory McCrossan Jan 19 '21 at 13:47
  • reference: https://stackoverflow.com/questions/15657686/jquery-event-detect-changes-to-the-html-text-of-a-div – D. Seah Jan 19 '21 at 15:01

2 Answers2

0

You can call it simply like:

$('body').bind('DOMSubtreeModified', function(){alert('changed');});

$('body').append('<h1>hello</h1>');
0
document.getElementById("divId").addEventListener("DOMSubtreeModified", (event)=>{
    console.log(event)
});