How to convert an HTMLcollection to a vector in clojurescript?

Viewed 182

I'm trying to apply a function to each element that has a certain class name like so:

(map #(js/console.log "element is " %) 
         (.getElementsByClassName js/document "some-class"))

But I suppose this doesn't work because getElementsByClassName returns an htmlCollection and not a vector. I tried wrapping getElementsByClassName with js->clj and Array.from, but neither works. How to convert this htmlCollection to a vector so that I can apply the function to each element?

1 Answers

You need to use the array-seq function, like this:

(array-seq (js/document.getElementsByClassName "foo"))

It will convert your HtmlCollection instance to a ClojureScript sequence.

Related