jQuery + Validation plugin: add/remove class to/from element's parent
- by FreekOne
Hi guys,
I'm working with the jQuery Validation plugin and I wrote the following code which adds a class to the element's parent if not valid (as well as inserting the actual error message at a particular location within the parent):
errorPlacement: function(error, element) {
element.parent().addClass('error');
error.insertBefore(element.parent().children("br"));
}
This works, however, if a field's content is corrected and becomes valid, the class obviously doesn't get removed from its parent (actually, neither does the error element, instead it just gets a display: none; CSS property). How can I check if an element becomes valid and remove its parent class if so ?
Any help would be much appreciated, thank you !