I'm trying to implement the bootstrap 4 loading spinner in button as in Bootstrap Spinners.
Below is what I'm doing in code
my.html
<form class="form-inline" id="topicForm" action="" method="POST">
<input type="text" id="inputTopic" name="topic" class="form-control mb-2 mr-sm-2" placeholder="Topic of interest" required autofocus/>
<button type="button" id="btnFetch" class="btn btn-primary mb-2">Submit</button>
</form>
my.js
$(document).ready(function() {
$("#btnFetch").click(function() {
// load data via AJAX
fetch_data($("#inputTopic").val());
// disable button
$(this).prop("disabled", true);
// add spinner to button
$(this).html(
`<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>Loading...`
);
});
});
This works except that the spinner as shown in bootstrap doc is not showing up. The button text is changing to Loading...
as expected. Wanted to know what is that I'm not doing right to the spinner inside the button.
https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css
– user3206440