0

I have a site where the content of a specific div updates without doing a page-load. This messes up a small jQuery script which only fires upon page-load.

I need a trick to reload that specific jQuery script whenever the content of the DIV is refreshed. I tried .on('change') but no sure if that is the best approach.

I can detect change in the Div is by monitoring the change in classes added to the div. Or maybe some sort of content supervision.

The script runs under document ready, should I put it in a function instead to make it easier to "fire at will" ?

MSQ
  • 489
  • 5
  • 15
XanderMan
  • 137
  • 1
  • 15
  • Does this answer your question? [jQuery Event : Detect changes to the html/text of a div](https://stackoverflow.com/questions/15657686/jquery-event-detect-changes-to-the-html-text-of-a-div) – MSQ Mar 24 '21 at 06:59
  • Dear @XanderMan, for javascript or jquery if it comes on page, then never goes, you think to add your jquery with dynamic parameter of your div, rather than reload – Ajay2707 Mar 24 '21 at 07:20

1 Answers1

0

If you are yourself updating the content you can add a script with in new content, that will call a function that already exists on that page. That function just needs to have a flag that can tell that page whether content is updated. Now if the content is updated, you can get new classes of that new content and target those new classes.

Or you can do it with MutationObservation https://stackoverflow.com/a/42805882/1351883

Or Just head over to This link

MSQ
  • 489
  • 5
  • 15