I try to select the "checkbox-group" from $this
element because in the form I could have many checkbox-group.
Actually I'm doing this in jQuery in order to display an error message.
$(document).delegate("input[type=checkbox]", "click", function()
{
$(".required_custom").remove();
if(!$(this).prop('required') && !$(this).is(':checked')){
$('.checkbox-group').after('<br class="required_custom" ><span class="required_custom" style="color:red">Au moins une case doit être coché</span>');
}
});
But with this code I'm displaying this error message to some others checkbox-group.
How can I use the "after" method in order to select only $this
checkbox-group ?
Thanks in advance. My html look like this with just one checkbox-group in the example but as I said before I could have many others.
<div class="checkbox-group">
<div class="checkbox">
<input name="checkbox-group-1547545912597[]" id="checkbox-group-1547545912597-0" aria-required="true" value="1" type="checkbox" class="user-error" required="required" aria-invalid="true">
<label for="checkbox-group-1547545912597-0">Option 1</label></div><div class="checkbox"><input name="checkbox-group-1547545912597[]" id="checkbox-group-1547545912597-1" aria-required="true" value="2" type="checkbox" required="required">
<label for="checkbox-group-1547545912597-1">Option 2</label>
</div>
</div>