calling DOM methods
See original GitHub issueIf an element gets rendered by a choo view, and I need to invoke a method on that element in response to an action, what is the proper way for making that call?
For example scrollIntoView()
, focus()
, normalize()
, select()
, etc.
In React, I’d use lifecycle methods for this. Would it make sense to add similar hooks to choo?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top Results From Across the Web
JavaScript DOM Methods - W3Schools
HTML DOM methods are actions you can perform (on HTML Elements). HTML DOM properties are values (of HTML Elements) that you can set...
Read more >Introduction to the DOM - Web APIs | MDN
The Document Object Model (DOM) is the data representation of the objects that comprise the structure and content of a document on the...
Read more >How to call multiple functions with DOM and Javascript
I have created multiple functions and am having trouble calling each one. The first one is the only one that will call. The...
Read more >Calling DOM methods from Elm - Learn
Unfortunately elm/html does not have a DOM method primitive. The problem with using Html.Attributes.property "setCustomValidity" (JSON.Encode.
Read more >Top 10 Essential JavaScript DOM methods List
Top 10 Essential JavaScript DOM methods List · 1) getElementId. getElementId is a method to access any element virtually. · 2) ...
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
Note that you’ll have to use query selectors in timeouts because once the view is patched onto the dom, there’s no guarantee the element created by the view will still exist. Because choo uses morphdom to apply dom updates, if an element already exists in the dom, it simply gets updated rather than replaced. So if your view creates a
<div>
each time it runs, and you save a reference to that<div>
inside your view and refer to it in a setTimeout callback, it will only work on the first render. Because future renders simply patch the existing<div>
with the one they created.Example: http://requirebin.com/?gist=7721c651eb58622669112c9391d9c1b8
Oh, cool. The timeout callback doesn’t give me the parentElement sugar but is good enough. Coming from React, I assumed DOM updates in Choo are also asynchronous.