Add load listener
See original GitHub issueHey guys how can i add eventlistener in stimulus way something like this
var div = document.getElementsByTagName("div")[0];
// does not work (console is not written to when page loads)...
div.addEventListener("load", function(){console.log("div load event")}, false);
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Window: load event - Web APIs - MDN Web Docs - Mozilla
The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets, scripts, iframes, and images.
Read more >How to Handle the JavaScript onload Event
The image's load event ... The load event also fires on images. To handle the load event on images, you use the addEventListener()...
Read more >Why doesn't document.addEventListener('load', function) work ...
The problem is WHEN the event is added and EXECUTED via triggering (the document onload property modification can be verified by examining ...
Read more >onload Event - W3Schools
The onload event occurs when an object has been loaded. onload is most often used within the <body> element to execute a script...
Read more >GTMTips: Add A Load Listener To Script Elements - Simo Ahava
Tip 66: Add a load listener to script elements. There are two ways you can go about this. The first one is to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Have you tried connect function? This gets called when the dom element connects to stimulus.
There is no
load
event for non-media elements (like<div>
s). Are you referring to thewindow
load event?Stimulus doesn’t do any rendering of its own so I’m not sure what you’re referring to here.
Stimulus provides two callbacks for that,
initialize()
andconnect()
, documented here: https://stimulusjs.org/reference/lifecycle-callbacksThe best place for questions like this is our community forum: https://discourse.stimulusjs.org. Feel free to continue the discussion there.