When I press a <button>
, I want to wait for an asynchronous function, then add some classes to the <button>
, but it doesn’t work. I want to use jQuery to do this.
Here is my code:
$("#btnSta").addEventListener("click", () => {
getAccount().then(addresses => {
$("#btnSta").classList.add('opacity-50 cursor-not-allowed');
});
});
2
Answers
You are trying to combine the DOM API (
.classList
) with jQuery. Instead, you should only use jQuery functions. The equivalent jQuery is this:You can also change your
.then
statement to the newer async/await syntax.As noted you are referencing vanila javascript methods on jquery selectors. Change parts
to
and
to