0

I am using JQuery-Validation-Plugin (http://docs.jquery.com/Plugins/Validation/). Now, I want to add a css-style class to an existing HTML-Element only after validate() was actually called. How to handle this? Thanks in advance.

// take first form, validate and add css-style class to existing elements ...
var allForms = jQuery('form');
var mainForm = allForms.eq(0);
var $mainForm = jQuery(mainForm);
$mainForm.validate({
            submitHandler : function(form) {
                form.submit();
            },
            rules : {
                "user-name" : {
                    required : true
                },
                "password" : {
                    required : true,
                    minlength : 3
                }
            },
            messages : {
                "user-name" : {
                    required : "Nutzernamen-Eingabe ist erforderlich."
                },
                "password" : {
                    required : "Passwort-Eingabe erforderlich.",
                    minlength : "Mindestlänge noch nicht erreicht."
                }
            }
        });
// CSS-Klasse fuer 
jQuery('.label').addClass('repositionLabelAfterErrorMessage');
1
  • 1
    In your code $mainForm === mainForm Commented Apr 27, 2012 at 9:19

1 Answer 1

2

I am not sure that you are looking for this or not, You can use errorClass property. Check this link http://docs.jquery.com/Plugins/Validation/validate#toptions

$(".selector").validate({
   errorClass: "invalid"
})

This will add css class to the error reporting label.

Sign up to request clarification or add additional context in comments.

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.