I wanted to implement a walkthrough tutorial but to do that I realised I needed to be able to select HTML elements from a property value (eg. name or id), ie get the value of a property from an HTML node. I think there currentlyis no way of getting an element's name in elm: could anybody please confirm? Does that mean I need to add something to virtual-dom package?
Asked
Active
Viewed 539 times
1 Answers
1
No, there is no way to really read a tree of Virtual DOM in Elm. If you look at the source for VirtualDom.elm, you'll see that nearly every function is implemented in native JavaScript, in the Native/VirtualDom.js file.
Sure, you could write some kind of native API to cheat the system and inspect the html like you're talking about, but the Virtual DOM was never meant to be used or queried in that way. The model with which you build your view should be the source of truth. Perhaps if you tweaked your design a bit, you would find that you don't really need this requirement after all.

Chad Gilbert
- 36,115
- 4
- 89
- 97
-
I don't see what the problem would be. Sure, I can modify my model. But that's the whole point of a walkthrough library: to be able to operate on any view, given a list of element names and a matching description. The idea is to create a module that can wrap any model,view, update. – Deimos Jan 17 '16 at 19:40
-
The problem is that the Virtual DOM code isn't written in a way that exposes its internals to Elm, so if you have to access the html in the way you're talking about, you're going to have to do it with native JavaScript at some point. It would be nice if that weren't the case, but I assume those decisions were made more for performance reasons. – Chad Gilbert Jan 17 '16 at 20:18