I try to use .unmask()
function after .blur()
(jQuery
), but it did not worked.
Please help, this is my code:
$('.cnpj').focus(function()
{
$(this).mask('99999999/9999-99');
})
.blur(function(e)
{
if($(this).val().length == 0)
{
var mask = '99999999/9999-99';
$(this).unmask(mask);
$(this).val('CNPJ');
}
});
Here is the HTML code:
<input type="text" id="cnpj" name="cnpj" class="cnpj empty entriesFormInput01" value="CNPJ" />
My goal is that when the user don't put any value in the input, the input return with the same value='CNPJ'
, because I have a lot of input in the form and the label is the value, if the user focus in one input and leave, the input will be empty if no value and i want to, when he leaves the input without a value the first value came back again.
First of all I think that jQuery mask() function doesn't exists as default. There is an plugin for jQuery which can be used like that, is that right? I've found this plugin. I think your code didn't worked because you didn't load this plugin or another one.