-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add: Explain how to run a function inside an inline script after the dom is loaded #1407
Comments
Thanks for this comment @paolotiu, and for being willing to make a PR! Would you be willing to just type in here what you would PR, so we can take a look at it, and think about where (on which page, in which section) it might actually best go? |
Hi @paolotiu - just following up here: are you still willing to give an example here of what you would PR, and where you think it would go in the docs? |
Hi @sarah11918! Sorry for the late reply. Here's a draft of what I would write. is:inline doesn't get processed by the astro compiler, so it will load as is where it is placed. This means some dom contents may not have loaded when the script runs. If you want to target dom nodes, it is recommended to use
|
I'm not sure that documenting how to use As for Thanks for bringing this to our attention! |
Agree! I think clarifying |
When using an
is:inline
ordefine:vars
on a script it becomes inlined in the served code 1:1. So, when someone wants to target an element further down the html (ex.document.querySelector("#footer")
), they might be inclined to usedefer
orasync
since that's what is taught in vanilla sites. It won't work though since thedefer
orasync
attributes don't actually apply.I think we should add in the docs how to achieve this behavior using
document.addEventListener("DOMContentLoaded, fn)
Willing to make a pr btw
The text was updated successfully, but these errors were encountered: