3

I know I can get an Element by id with Browser.Dom.getElement.

But how can I get a List Element by classname?

Dull Bananas
  • 892
  • 7
  • 29
Amparo
  • 784
  • 1
  • 4
  • 21
  • Could you describe why you need that function, what is the actual problem you are trying to solve? Usually there are better ways to solve UI scenarios than querying DOM. Perhaps by modeling the state such that no DOM queries are required. – Jigar Jul 16 '20 at 10:42

1 Answers1

2

As of Elm 0.19, the browser package doesn't expose any other helper functions to query the DOM. The getElement function itself is directly calling a kernel function:

getElement : String -> Task Error Element
getElement =
    Elm.Kernel.Browser.getElement

Depending on what you want to do specifically, you might want to write a JavaScript function that queries the elements, reads the interesting bits, and makes the result accessible to your Elm application through the ports system.

For instance, take a look at the elm-dom-ports package for inspiration. It exposes document.querySelectorAll() function as a port and you can catch its result by subscribing to querySelectorAllResponse.

viam0Zah
  • 25,949
  • 8
  • 77
  • 100