append error msg to label
Hi, i'm very new to JQuery.I really need help:
I have a form.I need to display an asterick next to the label if field is not validated and remove it if input it valid.
It's appending , but as many as wrong characters are typed in and removing all asterics at once from all invalid fields
This is what I'm doing now:
function validateHighlightError(element) {
$(element).addClass('failed-validation');
$(element).prevAll("label").css('color','#FF0000').append('<span class="msg">*</span>');
}
function validateUnhighlightError(element) {
$(element).removeClass('failed-validation').prevAll("label").css('color','#000000');
$(element).prevAll("label").css('color','#000000');
$('.msg').remove();
}
function validateErrorPlacement(element) {
$(element).click(function(){ $(element).attr({ value: '' }) });
}
What is the right way?
Thanks a lot for any advice.