3

I'm using the jquery.maskedinput plugin to create a mask for a phone number field:

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

Using a modification of Ryan Bates's nested form, I have a form where multiple phone numbers can be added dynamically via an "Add phone number" link. This link creates additional inputs, but the mask functionality is not applied. I am aware of the live() method in jQuery but am not sure if/how it can be used to apply the mask() method. Is there a way to apply this mask to dynamically created inputs?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
robertwbradford
  • 6,181
  • 9
  • 36
  • 61

1 Answers1

3

To answer my own question... I used the jquery.livequery plugin to do the following:

$('input[type="tel"]').livequery(function() {
  $(this).mask("(999) 999-9?999");
});
robertwbradford
  • 6,181
  • 9
  • 36
  • 61