I want jQuery validator to add a class to the form element's parent

Posted by Eystein on Stack Overflow See other posts from Stack Overflow or by Eystein
Published on 2010-06-18T06:25:23Z Indexed on 2010/06/18 6:33 UTC
Read the original article Hit count: 166

Filed under:
|

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();

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about validation