Skip to content
Advertisement

Adding CSS loader to HTML button click

I’m trying to add a “loader” while my flask application runs a task.

Here is my HTML for for my button

JavaScript

Here is the CSS that I’ve added:

JavaScript

Any ideas on how to call this correctly?

Advertisement

Answer

Make it visible from the start, without ever showing it with javascript. Then hide it with js like so:

JavaScript

EDIT: I now realize you said on button click in the title. I am assuming you want to hide the loading screen on button click? If not correct me in a comment. Otherwise, use this code:

JavaScript

P.S.

Your script should be at the bottom of the body, and your CSS and JS (and my code) reference #loader, when the body has <div id="loading">

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement