how to format variable with jquery mask

0

I use the jQuery Mask Plugin v1.13.4 plugin

I have a div where I enter a value as follows:

$('#v_pg').text('PAGA R$ ' + valor_pago);

Use Jquery to update the value inside the div. But I wanted it to be formatted by the Mask as follows:

$('').mask('00.000.000,00', {
    reverse: true
});

Does anyone know how to do this? or in any other way?

    
asked by anonymous 30.11.2016 / 14:00

1 answer

1

In your div , try to separate the content you want to mask from static text.

Something like this:

<div id="#v_pg">
   PAGA R$ <span class="valor_pago"></span>
</div>

Finally, you can put the mask as follows:

$('.valor_pago').mask('00.000.000,00', {
    reverse: true
});

It should work.

Another alternative is to use the data-mask attribute in the element. I've never particularly tested on elements that are not inputs but, theoretically, should work:

<div id="#v_pg">
   PAGA R$ <span class="valor_pago" data-mask="00.000.000,00"></span>
</div>

If you have questions, you can ask in the comments.

    
30.11.2016 / 14:09