Search code examples
onchangeemoticons

Is it possible to detect when a new element is detected


I'm working on this script that have emoticons work on the Campfire Chat. I want to know if it is possible to detect when there is a change to an element (A DIV).

For example if I append something to that element I can use so code to see that it has change. Is it possible?


Solution

  • Capture Mutation Events if you want to support this HTML5 feature. Otherwise periodically walk over the DOM tree looking for the changes.

    If it's just text you can use documenttext property which crunches all the text in the doc to a string. And see if that matches the documenttext the last time you polled.