package js_of_ocaml

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

DOM binding

This is a partial binding to the DOM Core API.

DOM objects

class type 'node nodeList = object ... end

Specification of NodeList objects.

type nodeType =
  1. | OTHER
  2. | ELEMENT
  3. | ATTRIBUTE
  4. | TEXT
  5. | CDATA_SECTION
  6. | ENTITY_REFERENCE
  7. | ENTITY
  8. | PROCESSING_INSTRUCTION
  9. | COMMENT
  10. | DOCUMENT
  11. | DOCUMENT_TYPE
  12. | DOCUMENT_FRAGMENT
  13. | NOTATION
module DocumentPosition : sig ... end
class type node = object ... end

Specification of Node objects.

class type attr = object ... end

Specification of Attr objects.

class type 'node namedNodeMap = object ... end

Specification of NamedNodeMap objects.

class type element = object ... end

Specification of Element objects.

class type characterData = object ... end

Specification of CharacterData objects.

class type comment = characterData

Specification of Comment objects

class type text = characterData

Specification of Text objects.

class type documentFragment = node

Specification of DocumentFragment objects.

class type 'element document = object ... end

Specification of Document objects.

Helper functions

val insertBefore : node Js.t -> node Js.t -> node Js.t Js.opt -> unit

insertBefore p n c inserts node n as child of node p, just before node c, or as last child if p is empty. The expression insertBefore n c p behave the same as p##insertBefore n c but avoid the need of coercing the different objects to node t.

val replaceChild : node Js.t -> node Js.t -> node Js.t -> unit

The expression replaceChild p n c behave the same as p##replaceChild n c (replace c by n in p) but avoid the need of coercing the different objects to node t.

val removeChild : node Js.t -> node Js.t -> unit

The expression removeChild n c behave the same as n##removeChild c (remove c from n) but avoid the need of coercing the different objects to node t.

val appendChild : node Js.t -> node Js.t -> unit

The expression appendChild n c behave the same as n##appendChild c (appends c to n) but avoid the need of coercing the different objects to node t.

val list_of_nodeList : 'a nodeList Js.t -> 'a Js.t list
type node_type =
  1. | Element of element Js.t
  2. | Attr of attr Js.t
  3. | Text of text Js.t
  4. | Other of node Js.t
val nodeType : node Js.t -> node_type
module CoerceTo : sig ... end

Events

type (-'a, -'b) event_listener

The type of event listener functions. The first type parameter 'a is the type of the target object; the second parameter 'b is the type of the event object.

class type 'a event = object ... end
class type ['a, 'b] customEvent = object ... end

Event handlers

val no_handler : ('a, 'b) event_listener

Void event handler (Javascript null value).

val handler : ('e event Js.t as 'b -> bool Js.t) -> ('a, 'b) event_listener

Create an event handler that invokes the provided function. If the handler returns false, the default action is prevented.

val full_handler : ('a -> 'e event Js.t as 'b -> bool Js.t) -> ('a, 'b) event_listener

Create an event handler that invokes the provided function. The event target (implicit parameter this) is also passed as argument to the function.

val invoke_handler : ('a, 'b) event_listener -> 'a -> 'b -> bool Js.t

Invoke an existing handler. Useful to chain event handlers.

val eventTarget : < .. > as 'a event Js.t -> 'a Js.t

Returns which object is the target of this event. It raises Not_found in case there is no target (if the event has not been triggered yet)

type event_listener_id
module Event : sig ... end
val addEventListenerWithOptions : < .. > Js.t as 'a -> 'b Event.typ -> ?capture:bool Js.t -> ?once:bool Js.t -> ?passive:bool Js.t -> ('a, 'b) event_listener -> event_listener_id

Add an event listener. This function matches the option-object variant of the addEventListener DOM method, except that it returns an id for removing the listener.

val addEventListener : < .. > Js.t as 'a -> 'b Event.typ -> ('a, 'b) event_listener -> bool Js.t -> event_listener_id

Add an event listener. This function matches the useCapture boolean variant of the addEventListener DOM method, except that it returns an id for removing the listener.

val removeEventListener : event_listener_id -> unit

Remove the given event listener.

val preventDefault : 'a event Js.t -> unit

Call this to prevent the default handler for the event. To stop propagation of the event, call Dom_html.stopPropagation.

val createCustomEvent : ?bubbles:bool -> ?cancelable:bool -> ?detail:'b -> ['a, 'b] customEvent Js.t Event.typ -> ('a, 'b) customEvent Js.t

Create a custom event of given type.

Other DOM objects

class type stringList = object ... end
OCaml

Innovation. Community. Security.