JQuery how to set a value in a field with CPF mask?

1

I have an input using an example CPF mask:

$("#cpfDependente").mask('000.000.000-00');

and I'm trying to set a value in the input this way

$("#cpfDependente").val(dependente.cpf);

It correctly directs the problem is that the mascara does not solve the problem? Thank you!

    
asked by anonymous 16.11.2015 / 20:35

2 answers

0

The solution I found was to add the data-mask="000.000.000-00" masquerade property in the HTML itself:

<input class="form-control" id="cpfDependente" name="cpfDependente" type="text" data-mask="000.000.000-00"/>
    
16.11.2015 / 21:37
3

Invert the order.

Add this command:

$("#cpfDependente").val(dependente.cpf);

Then add the mask:

$("#cpfDependente").mask('000.000.000-00');
    
16.11.2015 / 20:56