I'm trying to get a submit button to change to a loading spinner with the text "Loading..." using JavaScript like the image below.
I'm able to update the innerHTML for the button, but I'm having trouble changing the span class, which controls the actual spinner.
Here is my html for the button:
<button class="btn btn-primary mx-3" id="submit" onclick="loading()" type="submit">
<span id="button_span"></span>
Submit
</button>
And here is the JavaScript:
function loading() {
var button = document.getElementById("submit");
button.innerHTML = "Loading...";
var span = document.getElementById("button_span");
span.classList.add("spinner-grow");
span.classList.add("spinner-grow-sm");
}
Any help would be greatly appreciated. Thanks.