JQuery, insertBefore, validation, posting error message

I am using insertBefore on error to add validation messages, each one below each other, as I want the order of the messages to go from top to bottom.

I am using a hidden input at the very bottom of the parent to provide the element for the insertBefore argument.

Is there a way to insert from below without using a hidden hidden item?

If I use absolute positioning, there is room for space, for example 3 tiered posts, the middle one is missing as there is no absolute positioning collapse.

Update

So if I want to insert before "zzz", is there a way to do it without "zzz"?

<div>
    <input id="zzz" type="hidden">
</div>

      

+2


a source to share


3 answers


I tried append as well as appendTo. I agree that they should work, and they are, but, in the context of a validation plugin, for some reason, both functions use the parent of the matched item instead of the matched item and append to the wrong item. Also, the validation feature stopped working with the add.

I ran a dummy element replacement and raised the element that was used in its place and got stuck with insertBefore.

This worked:



errorPlacement: function(error, element) {
    error.insertBefore("#zz")
    error.wrap("<p>")

      

It wasn't - it was added to the parent #zz and the wrap function doesn't work.

errorPlacement: function(error, element) {
   ("#zz").append(error);
   error.wrap("<p>");

      

+1


a source


Are you looking for $.append()

?



+1


a source


If you want to insert into a div without hidden input, you will need to find the link to the div you want to insert and then use the $ .append () function.

$('ref-to-div').append('<span>message</span>');

      

+1


a source







All Articles