0

I'm sure this has come up before, but I can't seem to search the right wording to find anything related.

I have an object i created with JQuery. (will actually a 3rd party plugin created it)

Since is was created after the dom was formed, it's not found as an object by JQuery.

I want to appendTo() this created object.

Isn't there a JQuery command that says "check if new elements have been added to the dom?

  • Can you show an example of what you want to do in a http://jsfiddle.net? As little code as possible to reproduce your problem would greatly improve our ability to help you – Stephan Muller Mar 28 '15 at 12:21

2 Answers2

0

That's called event delegation. You can do this within the on method:

$('table').on('click', 'td', function() {
  $( this ).addClass('highlight');
});

This adds the highlight class to all td elements, even those created after the event declaration.

However, in your particular example, appendTo() should be able to find newly-created elements, so I can't think of why event delegation is needed in that context.

Rick Hitchcock
  • 35,202
  • 5
  • 48
  • 79
0

There is the JS MutationObserver method which can detect DOM tree update. You can check if update correspond to your added object. An other helpful question here.

Community
  • 1
  • 1
Rémy J
  • 108
  • 5