Conditionally wrap error message in jQuery Validation
I need to wrap an error message only if a certain condition is true. This means I can't use the wrapper property since it would always wrap the error message. So I'm using errorPlacement()
with the following code.
errorPlacement : function(error, element) {开发者_如何转开发
if (condition == true) {
error.wrap("<li></li>").appendTo(element);
}
else {
...
}
}
Somehow this code doesn't have the message wrapped. First, am I right to replace errorPlacement()
to get what I want done? Second, what am I doing wrong to wrap the HTML text?
Try $('<li></li>').append(error).appendTo(element);
精彩评论