redconservatory redconservatory - 1 year ago 196
jQuery Question

jQuery validate add class to error element?

I have the following code using jQuery Validate.

debug: true,
highlight: function (element, errorClass, validClass)

unhighlight: function (element, errorClass, validClass)

Is there a way to add a class to the errorElement, 'span' so that it's...:

<span class="help-inline error">Message</span>

Answer Source

When you specify the errorClass, there's nothing stopping you from making it two things: "help-inline error", i.e.:

    debug: true,
    errorClass: 'error help-inline',
    validClass: 'success',
    errorElement: 'span',
    highlight: function(element, errorClass, validClass) {
    unhighlight: function(element, errorClass, validClass) {

Note that you have to use version 1.10 of jQuery Validate to support this. Earlier versions only allow one errorClass.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download