Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get jquery default style after changing input style?

Tags:

jquery

css

input

I have a text input which I validate its value when event "blur" triggers . when the value is not valid , I change the input background color , and when I resolved the error I want the original color and style of the input to be set again to it . but what's happening that I'm losing the original style after resolving the error or getting the error , in general that's happening when changing input's style . I tried to look for the original style to set it again but I couldn't find it in jqueryui styles . need your help :

HTML Code :

<input type='text' name='val1' id='val1'/> 

jQuery Code :

function is_numeric(value)
{
    var pattern= new RegExp(/^[0-9]+$/);
    return pattern.test(value);
}

$(document).ready(function ()
{
 $('#val1').blur(function()
    {
        if(!is_numeric($('#val1').val()))
        {
            $('#val1').css('background-color','#E65050');
        }
        else
        {
            $('#va1').css('background-color','white '); /// here ??
        }
    });
 });
like image 264
HalaKuwatly Avatar asked Jan 26 '26 09:01

HalaKuwatly


1 Answers

please use class see the DEMO

CSS

.error {background-color:#E65050}

jQuery

function is_numeric(value)
{
    var pattern= new RegExp(/^[0-9]+$/);
    return pattern.test(value);
}

$(document).ready(function ()
{
 $('#val1').blur(function()
    {
        if(!is_numeric($('#val1').val()))
        {
            $('#val1').addClass('error');
        }
        else
        {
            $('#va1').removeClass("error");
        }
    });
 });
like image 70
GajendraSinghParihar Avatar answered Jan 27 '26 23:01

GajendraSinghParihar