I'm using this jQuery plugin: http://docs.jquery.com/Plugins/Validation/validate and it seems to always put the messages after the input element. is there a way to get them to append to before the element instead of after?
3 Answers
Use errorPlacement to control will allow you to put error message on specific place.
$("#myform").validate({
errorPlacement: function(error, element) {
error.appendTo(element.parent("td").next("td") );
}
});
Here are a few samples of errorPlacement with error options as well
- error.appendTo(element.parent("div").next("div"));
- error.appendTo($('#id'));
- error.insertAfter(element);
- error.insertBefore(element);
For custom error message and control creation
errorPlacement: function(error, element) {
var elementForm = "", containerError = "";
offset = element.offset();
elementForm = element.attr("name");
containerError = "#" + elementForm + "error";
error.prependTo(containerError);
error.addClass('message');
}