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
parentsmethod instead ofparentas