1

I would like to execute a function when new dom elements are added via ajax, somewhere in the body, by a 3er party JS.

The function i want to execute is jqueryui's tooltip(), which changes title attribute into nice tooltips.

The problem happens when a 3rd party JS adds new elements to many differents div's, and the new element's 'title' attribute are not being substituted by tooltips. So I need to do again:

$('*').tooltip()

I think I need something checking if new elements have been added to the body, and run the function on them.

Any ideas ?

arod
  • 13,481
  • 6
  • 31
  • 39

2 Answers2

0

Have a look at liveQuery it does what you need.

Moin Zaman
  • 25,281
  • 6
  • 70
  • 74
0

I did the same in one of my project which is I needed to listen to the DOM changes., e.g. DOM append, remove, attribute, and data changes.

Actually, the browser itself provides the native function/DOM changes listener which is the "Mutation Observer".

These links WILL help you :

  1. https://github.com/kapetan/jquery-observe
  2. Is there a JavaScript/jQuery DOM change listener?
  3. https://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#mutationobserver
Community
  • 1
  • 1