I have a simple validation for my input elements:
$("#forma").validate({
errorClass: "red"
});
$("#input").each(function(index, elem) {
var rules = {
required:true
};
$(elem).rules("add", rules);
});
So, when error occurs - error messages are displayed and those error messages are inside label elements. For example, if you forget to enter the last name and you click submit button - this label element will be added:
<label id="lastname-error" class="red" for="lastname">This field is required.</label>
Now, I would like to add empty span element inside of those labels, at the beginning (prependTo) with the background-image and other CSS properties, so it will look like this:
<label id="lastname-error" class="red" for="lastname"><span class="myspan"></span><This field is required.</label>
I guess that this can be done by some event, like: when an error occurs - execute this:
var html = "<span></span>";
$(html).css({
"background-image": "url('../images/arrowRight.png')",
"padding-right": "26px",
"background-repeat: no-repeat"
}).prependTo("label.red");
Do you know how can I do this?