Alex Rivera | Logout

jQuery validate add class to error element?

Asked 2012-03-29T16:23:17.573
13

I have the following code using jQuery Validate.

$("#register").validate({
    debug: true,
    errorClass:'error',
    validClass:'success',
    errorElement:'span',
    highlight: function (element, errorClass, validClass) { 
        $(element).parents("div.control-group")
                  .addClass(errorClass)
                  .removeClass(validClass);
    }, 
    unhighlight: function (element, errorClass, validClass) {
        $(element).parents(".error")
                  .removeClass(errorClass)
                  .addClass(validClass); 
    }
});

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

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

1 Answer

-1
$(".error").addClass('help-inline')

will add the help-inline class to all DOM elements with the error class already.

Is that what you are looking for?

answered 2012-03-29T16:42:34.487

Your Answer