Apply a plugin's method to dynamically created elements?
I'm using the jquery.maskedinput plugin to create a mas开发者_如何学Gok 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?
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");
});
精彩评论