igorescobar / jQuery-Mask-Plugin

A jQuery Plugin to make masks on form fields and HTML elements.
http://igorescobar.github.io/jQuery-Mask-Plugin/
Other
4.77k stars 1.42k forks source link

<td>Programaticaly appended wont mask #703

Open ctpaula opened 5 years ago

ctpaula commented 5 years ago

Searched a lot on Git, on Docs and don't found anything that helped me. I know the mask work on "td" but I need to add a td when a button is clicked, in this case, the mask just dont work. What I need to do?

Made this jsfiddle with one example took from this issue (https://github.com/RobinHerbots/Inputmask/issues/1110) but put my problem in the button "tst".

https://jsfiddle.net/6w48vdej/

shayckspear commented 4 years ago

Hi, I think you need unmask before create a new obj, see code

$("#tstbtn").click(function(){ $(".mask-date").unmask(); $("#teste").append('930915'); $(".mask-date").mask("99/99/99"); });

luis-fss commented 3 years ago

Just re-apply the mask inside the event:

$("#tstbtn").click(function(){
    $("#teste").append('<tr><td class="mask-date">930915</td></tr>');
        $(".mask-date").mask("99/99/99");
});