The following won't work since sides is a Dom.nodeList
and DomTokenList.forEach
expects a Dom.domTokenList
.
open Bs_webapi.Dom;
external length : Dom.nodeList => int = "" [@@bs.get];
let sides = Document.querySelectorAll "#carousel > figure" document;
DomTokenList.forEach (fun item _ => print_endline item) (sides);
Paraphrased from the Reason Discord, courtesy of @anmonteiro:
Here is an example of how to
setAttribute
for each element in aNodeList
. Note,Element.ofNode
can be used to convert aDom.node
tooption Dom.element
.https://bucklescript.github.io/bucklescript/api/Js_array.html#VALforEach