I have a field that inserts HTML when a user submits my form. If there is an error it inserts the error message before the form field. However, if the user submits multiple times it inserts multiple error messages, I would like to simply replace the error message so that it only appears once. I've tried to use replace but I couldn't get this way to work.
The form works via ajax so we don't reload the page to remove the errors, I need a way of replacing / removing them using jQuery.
Here is my jQuery code.
$('<p class="form-error" id="' + errorKey + 'ErrorMessage">' + json.errors[errorKey] + '</p>')
.insertBefore(('[name="' + errorKey + '"]'))
divwith a unique id and add your created error message with .html