0

Is there a way to call a function on a specific selector that would apply to any element that matches that selector now, and in the future?

Just the way it works (before it was deprecated) with live.

Something like:

$('form.validate').live('create', validate);
Blazemonger
  • 90,923
  • 26
  • 142
  • 180
Bruno
  • 31
  • 4

1 Answers1

1

The equivalent of live in the current version is:

$('form').on('create', '.validate', validateFunction);

Now, since the create event is not a standard DOM event, it is you who fires it. You must have somewhere (for example when you render the form):

// ... create a .validate element
validateElement.trigger('create');

The on syntax above should catch this create event.

Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168