✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Javascript and Dash

Anyone know why this first bit of code works in a javascript file, alone

alert(“Hello! I am an alert box!!”);

…but this second bit of code doesn’t modify the element?

document.getElementById(“atinput_hist”).style.display = “none”;

Dash is cranky when it comes to javascript :frowning:

Is your post and mine similar? How to trigger a JavaScript function on load?

13 hours and I’m the only reply… Losing faith for my own issue. Sorry I don’t have an answer, but maybe neither of us are the only ones.

How are you calling the JS?

Hi Emil,
Thanks for responding. I’m just placing placing the JS in a file in the assets folder and letting it run.

When I place those files in a standard HTML document and let them run, they both work fine.

When I do the same with Dash, only the alert works.

I think that’s because the Dash components are generated dynamically, i.e. the JS is actually run before the elements are loaded. I guess it would work, if you use the solution i posted here,

to ensure that the JS is loaded after the components are loaded.

Thanks - will take a look!