40
rated 0 times
[
43]
[
3]
/ answers: 1 / hits: 28765
/ 7 Years ago, sun, march 19, 2017, 12:00:00
I would like to append a div
only if it's not already there. I am trying with this but it doesn't work:
$('#method_id').on('change', function (e) {
if ($(this).find(option:selected).data('method-column-id') != 1) {
if ($('#column_message').next('div').length)
$('#column_message')
.append('<div id=warning_message class=alert alert-danger><strong>Warning!</strong> Installed column and method do not match</div>');
} else {
$('.form-group').find('#column_message>.alert').remove();
}
});
And if I remove the second if-clause, it gets appended every time I select an option which passes first if-clause
Here is the HTML
<!-- Warning message -->
<div class=form-group>
<label for=group class=col-md-2 control-label></label>
<div id=column_message class=col-md-6>
</div>
</div>
More From » jquery