I have a field like the following:
<div class="control-group">
<label class="control-label" for="lname">Last Name</label>
<div class="controls">
<input class="span3" type="text" id="lname" name="lname" placeholder="Last Name" value=""/>
</div>
</div>
I'm trying the following jquery to validate some input and add the error class if needed:
var div = $("#lname").parent("div.control-group");
....
div.removeClass("success");
div.addClass("error");
Ideally I need to loop through several input and select fields to do my validation.
My current code isn't adding the error class. Any idea why?
You should use parents
method instead of parent
as
var div = $("#lname").parents("div.control-group");
div.removeClass("success");
div.addClass("error");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With