noway
noway

Reputation: 2585

Selecting elements which are created on the fly with jQuery

I am trying to implement a jQuery plugin listed here with something like:

$(document).(function($){
   $('input[id^="field-phone-"]').mask("0 (99) 999 9999");
});

It works fine normally. Yet, if I create another field run time, the selector does not select it. How can I make jQuery to be aware of that? I have seen the live thing, but do not know how to implement it.

Upvotes: 1

Views: 110

Answers (1)

Anthony Grist
Anthony Grist

Reputation: 38345

Using standard jQuery the simple answer is that you can't. You'll need to call the mask() function again at the same time as creating your new elements.

Upvotes: 3

Related Questions