Equivalent to document.getElementsByClassName

I can not find the equivalent of js_of_ocaml document.getElementsByClassName. What is the canonical way?

EDIT: I am using js_of_ocaml v2.5.

+4
source share
3 answers

It does not seem to exist.

The closest I can find is to use the attribute of classNameelements DOM_html( docs ) and DOM_svgelements ( docs ). Then you can iterate over the collection and get the desired item.

This was taken from the index method I was looking at.

However, the DOM document class has the tag name getElementById and getElementBy, as shown here .

method getElementById : Js.js_string Js.t -> 'element Js.t Js.opt Js.meth

method getElementsByTagName : Js.js_string Js.t -> 'element nodeList Js.t Js.meth

+1
source

, :

let getElementsByClassName (name : Js.js_string Js.t)
    : Dom_html.element Dom.nodeList Js.t =
  Js.Unsafe.meth_call
    Dom_html.document "getElementsByClassName" [|Js.Unsafe.inject name|]

Dom.document##getElementsByTagName. .

:

getElementsByClassName (Js.string "control")

, , OCaml Dom_html.getElementById. , , OCaml.

+1

I needed this function a few weeks ago, so I did a PR https://github.com/ocsigen/js_of_ocaml/pull/312

+1
source

Source: https://habr.com/ru/post/1589453/


All Articles