JQuery validation - how to set the title attribute to the error message
- by JK
In JQuery validation the default behavior on an error is to create a label like so:
<label for="FirstName" generated="true" class="error">This field is required.</label>
Is it possible to change it so that it will output this instead (with a title attribute set to the error message)?
<label for="FirstName" generated="true" class="error" title="This field is required.">This field is required.</label>
I've tried the highlight method, but the label has not been created yet:
$("#form").validate({
highlight: function (element, errorClass) {
var label = $("label[for=" + element.id + "]"); // but label doesn't exist yet so this doesnt work
if (label && label.length > 0) { // label.length is always 0
label.attr('title', label.text());
}
}
});