Note that depending on how they are used, badges may be confusing for users of screen readers and similar assistive technologies. While the styling of badges provides a visual cue as to their purpose, these users will simply be presented with the content of the badge.
Layout. Since Bootstrap applies display: block and width: 100% to almost all our form controls, forms will by default stack vertically. Additional classes can be used to vary this layout on a per-form basis. Form groups. The .form-group class is the easiest way to add some structure to forms. It provides a flexible class that encourages proper grouping of labels, controls, optional help text ...
Referenced the solution and now came up with this:
HTML:
<div id='alert' class='hide'></div>
Javascript:
function showAlert(message) {
$('#alert').html("<div class='alert alert-error'>"+message+"</div>");
$('#alert').show();
}
showAlert('variable');
Working jsfiddle.
Try this code hope it will help you :
$(document).ready(function(){
let text = $("#text");
let alert = $("#alert");
$("#form").submit(function(e){
e.preventDefault();
// ---------------
setAlert("success",text.val());
alert.toggleClass('d-none').toggleClass('d-none', 2000);
});
function setAlert(type, value) {
alert.html(`<b>${type} ! </b> ${value}`);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="p-4">
<div id="alert" class="alert alert-success d-none"></div>`
</div>
<form class="form-inline" id="form">
<div class="form-group mx-sm-3 mb-2">
<input type="Text" class="form-control" id="text" placeholder="Enter text">
</div>
<button type="submit" class="btn btn-primary mb-2">Alert</button>
</form>
you can use only method to achieve this.show
//$("#alert").alert("close");
$("#info").click(function() {
$("#alert").show();
});
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<form>
<div class="form-group">
<label class="" for="">
Checkbox <span class="glyphicon glyphicon-info-sign" id="info"></span>
</label>
<div class="checkbox">
<label>
<input type="checkbox" id="" value="option1" aria-label="..."> Sample
</label>
</div>
</div>
<div class="alert alert-info alert-dismissible" role="alert" id="alert" hidden>
<button type="button" class="close" onClick="$('#alert').hide();" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Note: </strong> Test... and that is that. <a href="#" class="alert-link">More info</a>
</div>
</form>