0

I have this jquery code :

var regexparam="([^a-zA-Z ])";                                                
if(thisValue.match(regexparam))                                    
{                                                                                                                                        
     $(parentId).children('span').addClass('red').html('✕  Firstname cannot contain numbers or symbols.');                                     
}
else if($.trim(thisValue)=="")                                    
{
    $(parentId).children('span').addClass('red').html('✕   Firstname cannot be empty.');                                        
}
else
{
    $(parentId).children('span').addClass('green').html('✔   So you\'re '+ thisValue+'.');                                
}    

The 'red' class is being rendered when the user inputs wrong information... While the 'green' class doesn't apply and revert back to it's default color.

I checked on the firebug and the class is being rendered and I can see that both green and red class is being applied to the element.

Here's my css:

.red{color:red;};
.green{color:green;};

3 Answers 3

1

Your css has snytax errors, remove the ; after each group

.red{color:red;}
.green{color:green;}
Sign up to request clarification or add additional context in comments.

1 Comment

Urggggggggh yeah syntax problem jeeez
0

Just use toggleClass() in spite of addClass().

Because probably whats happening is that the previous values are not getting overridden .

And you can also try using

.red{color:red !important;}
.green{color:green !important ;}

but do use this trick with caution

Comments

0

You can do .removeClass('red').removeClass('green').addClass('<requiredOne>')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.