Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 873387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:55:34+00:00 2026-05-15T10:55:34+00:00

How do I use jQuery validator to add/remove a classname (e.g. validate ) on

  • 0

How do I use jQuery validator to add/remove a classname (e.g. validate) on the form element’s parent <li> so I can style everything related to that element by only setting the one classname?

The markup is

<li class="validate">
    <label for="product">Product of interest <abbr title="Required field">*</abbr></label>
    <input id="product" type="text" name="product" value="" placeholder="e.g. school bench" class="required" minlength="2">

    <!-- Hidden by CSS unless parent has 'validate' class -->
    <label for="product" class="description">Please name a product.</label> 
</li>

and the default jQuery is

$("#commentForm").validate();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:55:34+00:00Added an answer on May 15, 2026 at 10:55 am

    Use the highlight and unhighlight options here to override where the errorClass (or validClass) gets applied:

    $("#commentForm").validate({
      highlight: function(element, errorClass, validClass) {
        $(element).closest('.validate').addClass(errorClass).removeClass(validClass);
      },
      unhighlight: function(element, errorClass, validClass) {
        $(element).closest('.validate').addClass(validClass).removeClass(errorClass);
      }
    });
    

    By default, the errorClass is “error” and get applied directly on the input element. For a better illustration, this is the default validate functions, when you don’t provide these options to .validate(), here’s what happens:

    $("#commentForm").validate({
      errorClass: "error",
      validClass: "valid",
      highlight: function( element, errorClass, validClass ) {
        $(element).addClass(errorClass).removeClass(validClass);
      },
      unhighlight: function( element, errorClass, validClass ) {
        $(element).removeClass(errorClass).addClass(validClass);
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use jquery validator plugin and form submit via ajax in
Hi I use jQuery validator for one form. It was working nice until today.
I use bassistance jQuery validation plugin to validate my inputs. I want to add
I'm trying to use jQuery validation plugin to validate a few form fields by
I'm trying to use the Jquery validation plugin to validate my form. I have
I'm using the Validator from jQuery Tools to validate my form (why jquery tools?
I use a jquery validation plugin and I need to add some extra checking,
I'm trying to use the Jquery builtin validator on my page. The issue is
All, I am trying to use JQuery's URL Validator plugin. http://docs.jquery.com/Plugins/Validation/Methods/url I have a
I'm trying to use a custom validator with jQuery Validation plugin. However, I'm unsure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.