diff options
Diffstat (limited to 'src/Lib/Dom/Element.ml')
-rw-r--r-- | src/Lib/Dom/Element.ml | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Lib/Dom/Element.ml b/src/Lib/Dom/Element.ml new file mode 100644 index 0000000..3e3b78a --- /dev/null +++ b/src/Lib/Dom/Element.ml @@ -0,0 +1,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 |