Been trying to crack this for days and I think I've got tunnel vision that can't see past my mistake!
I have an HTML button which when calling a javascript method and passing it true or false I want the button class to change as well as the innerHTML. Currently, I can only get the class to change. See the code below:
var buttonHandler = function () {
toggleButton(false);
getRecords();
};
var btn = document.getElementById("get-records");
btn.addEventListener("click", buttonHandler);
JS:
function toggleButton (loaded) {
btn.innerHTML = loaded ? "Get next" : "Loading...";
btn.classList.toggle("button-not-loading");
btn.classList.toggle("button-loading");
}
HTML (The button looks like this):
<button id="get-records" class="button-not-loading">Get next</button>
CSS: .button-loading { background-color:dodgerblue; color:white }
.button-not-loading {
background-color:lawngreen;
color:white
}