I am trying to display the error message for a group of radio buttons in a div with class "Errors". All input element's error messages display on the correct place except for this group of radio buttons.
HTML:
<ul>
<li><input type="radio" value="organic1" name="payment" />Organic1</li>
<li><input type="radio" value="organic2" name="payment" />Organic2</li>
<li><input type="radio" value="organic3" name="payment" />Organic3</li>
<li><input type="radio" value="organic4" name="payment" />Organic4</li>
<li><input type="radio" value="organic5" name="payment" />Organic5</li>
<li><input type="radio" value="organic6" name="payment" />Organic6</li>
</ul>
<br style="clear:both;">
<div class="Errors"></div>
JS:
$("#form").validate({
errorPlacement: function(error, element) {
if (element.is(":radio")) {
error.insertAfter(element.closest('ul.radio'));
error.addClass('.Errors');
// Also, I have tried all this but no use
//error.appendTo(element.closest('ul.radio').find('div.Errors'));
//$(element).closest('li').next().find('div.Errors').html(error);
//error.appendTo(element.parent().find('div.Errors'));
}
}
}
Please Advice,
To output the error in the
.Errorselement,I recommend using
errorLabelContainer:Here's a demonstration:
EDIT
With your current method, use
append():Or
appendTo():Or to insert errors after another element, use
after():Or
insertAfter():