blob: 3e3b78ac3573a631791c0236ca1a52cb85b1272b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
external setValue : Dom.element -> string -> unit = "value" [@@bs.set]
external setTextContent : Dom.element -> string -> unit = "textContent"
[@@bs.set]
external setStyle : Dom.element -> string -> unit = "style" [@@bs.set]
external setClassName : Dom.element -> string -> unit = "className" [@@bs.set]
external setAttribute : Dom.element -> string -> string -> unit = "setAttribute"
[@@bs.send]
external setAttributeNS : Dom.element -> string -> string -> string -> unit
= "setAttributeNS"
[@@bs.send]
external addEventListener : Dom.element -> string -> (Dom.event -> unit) -> unit
= "addEventListener"
[@@bs.send]
external appendChild : Dom.element -> Dom.element -> unit = "appendChild"
[@@bs.send]
external firstChild : Dom.element -> Dom.element Js.Nullable.t = "firstChild"
[@@bs.get]
external removeChild : Dom.element -> Dom.element -> unit = "removeChild"
[@@bs.send]
let removeFirstChild element =
match Js.toOption (firstChild element) with
| Some child ->
let () = removeChild element child in
true
| _ -> false
let rec removeChildren element =
if removeFirstChild element then removeChildren element else ()
let mountOn base element =
let () = removeChildren base in
appendChild base element
|