Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How can I use a custom CSS class for the error messages? I'd rather not style the standard label.error. I want to use a CSS class I already have.

share|improve this question

closed as not a real question by hohner, Andrew, ЯegDwight, rds, j0k Jan 21 '13 at 22:41

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
This question is really broad. whathaveyoutried.com –  Jay Blanchard Jan 21 '13 at 21:14
    
What's the difference? If you want to style ALL the error messages the same way, there's no reason not to use label.error. –  Blazemonger Jan 21 '13 at 21:17
    
It would be helpful to explicitly link to the validation library you are using. I'm pretty sure it's the bassistance.de jQuery Validate, but other people might be confused! –  Ryley Jan 21 '13 at 22:10

2 Answers 2

up vote 1 down vote accepted

There is an option for jQuery Validate called errorClass:

Use this class to create error labels, to look for existing error labels and to add it to invalid elements.

All you need to do is specify it in your original $.validate call:

$('#myForm').validate({
   errorClass:'myClass'
   //your options
});
share|improve this answer
    
thank you this is what i needed! –  heri0n Jan 22 '13 at 14:03

You could do something like that:

html:

<form action="">
    <ul>
        <li><input type="text" id="name" value="Your name" /></li>
        <li><input type="submit" id="submit" /></li>
        <li class="error">
            <span>Ops!</span>
        </li>
    </ul>
</form>

css:

form .error {display:none;}

jquery:

$('form').submit(function(){
    if($('#name').val()==''||$('#name').val()=='Your name'){
        $('form .error').css({display: 'block'});
    }
})
share|improve this answer
    
-1 for not properly using the plugin... or using it at all. It already has its own submitHandler event built-in, so no need to bind another function to form's submit event. Additionally, since he's using the validation plugin, why would he write a custom validation function that does its own validation external to the plugin? The answer makes no sense. –  Sparky Jan 21 '13 at 23:47
    
i am not veeery familiar with all the functions of the plugin, i just showed a way to fix the problem and this way works. its not the best way to solve the problem but it can fix the problem, its not efficiently but its effectively. you could -1 the answer if it didnt work at all right? thanks –  Ramon Vasconcelos Jan 22 '13 at 12:47
    
Why would you post an answer about something you're not familiar? I gave it a -1 because the answer is a really clumsy and impractical solution. Why would the OP use the validation plugin if he wanted to re-write validation code from scratch? And your answer may not actually work properly with the plugin. –  Sparky Jan 22 '13 at 14:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.