0

I have a form and I want to change the font size and colour of the error messages in css but I can't figure out how to do it.

$(document).ready(function() {
   $("#form1").validate({ 
      rules: {  
         credit: {
         required:true,
         creditcard: true
      },
      amount: { 
         required: true,
         min:(15),
      },
      firstname: "required",// simple rule, converted to {required:true} 
      surname: "required",// simple rule, converted to {required:true}   
      name2: "required",// simple rule, converted to {required:true}    
      surname2: "required",// simple rule, converted to {required:true}     
      name3: "required",// simple rule, converted to {required:true}  
   },

These are the messages, I don't want them to be the same size and colour as the form inputs and need to figure out how to change them

      messages: {
         firstname: "Please enter a first name",
         surname: "Please enter a surname",
         name2: "Please enter a first name",
         surname2: "Please enter a surname",
         name3: "Please enter a name",
      }      
   });
});
3
  • You haven't given any indication of how you've tried to set size & colour using CSS (or the HTML that this code works with), which makes it difficult to know what sort of answer you need. Commented Jan 20, 2013 at 18:42
  • use label.error in your css to customize jQuery.validate error messages. Commented Jan 20, 2013 at 18:42
  • If you want to use CSS, *use * CSS, not a jQuery method. Commented Jan 20, 2013 at 18:47

1 Answer 1

3

By default with the jQuery validate plugin, when you attempt to post a form with errors, it adds the classname error to all form elements which have failed validation. So:

<input type="text" name="firstname"/>

Will become:

<input type="text" name="firstname" class="error"/>

To change the styles, use something like this:

.error {
   color: red;
   font-size: 12px;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I was wondering why .error was being used in other answers.

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.