Apply plugin method to dynamically created elements?

I use the jquery.maskedinput plugin to create a mask for a phone number:

jQuery('input[type="tel"]').mask("(999) 999-9999");

Using a modification of the Ryan Bates nested form , I have a form in which you can add dynamically multiple phone numbers using the "Add Phone Number" link. This link creates additional inputs, but the functionality of the mask is not applied. I know about the live () method in jQuery, but I'm not sure that / how it can be used to apply the mask () method. Is there a way to apply this mask to dynamically created inputs?

+3
source share
1 answer

... jquery.livequery, :

$('input[type="tel"]').livequery(function() {
  $(this).mask("(999) 999-9?999");
});
+3

All Articles