Up

module Dom

: sig

DOM binding

This is a partial binding to the DOM Core API.

DOM objects

#
class type ['node] nodeList =
#
method item : int -> 'node Js.t Js.opt Js.meth
#
method length : int Js.readonly_prop

Specification of NodeList objects.

#
type nodeType =
# | OTHER
# | ELEMENT
# | ATTRIBUTE
# | TEXT
# | CDATA_SECTION
# | ENTITY_REFERENCE
# | ENTITY
# | PROCESSING_INSTRUCTION
# | COMMENT
# | DOCUMENT
# | DOCUMENT_TYPE
# | DOCUMENT_FRAGMENT
# | NOTATION
#
module DocumentPosition : sig

Specification of Node objects.

#
type t = private int
#
type mask = private int
#
val disconnected : mask
#
val preceding : mask
#
val following : mask
#
val contains : mask
#
val contained_by : mask
#
val implementation_specific : mask
#
val has : t -> mask -> bool
#
val add : mask -> mask -> mask
#
val (+) : mask -> mask -> mask
end
#
class type node =
#
method nodeName : Js.js_string Js.t Js.readonly_prop
#
method nodeValue : Js.js_string Js.t Js.opt Js.readonly_prop
#
method nodeType : nodeType Js.readonly_prop
#
method parentNode : node Js.t Js.opt Js.prop
#
method childNodes : node nodeList Js.t Js.prop
#
method firstChild : node Js.t Js.opt Js.prop
#
method lastChild : node Js.t Js.opt Js.prop
#
method previousSibling : node Js.t Js.opt Js.prop
#
method nextSibling : node Js.t Js.opt Js.prop
#
method insertBefore : node Js.t -> node Js.t Js.opt -> node Js.t Js.meth
#
method replaceChild : node Js.t -> node Js.t -> node Js.t Js.meth
#
method removeChild : node Js.t -> node Js.t Js.meth
#
method appendChild : node Js.t -> node Js.t Js.meth
#
method hasChildNodes : bool Js.t Js.meth
#
method cloneNode : bool Js.t -> node Js.t Js.meth
#
method compareDocumentPosition : node Js.t -> DocumentPosition.t Js.meth
#
class type attr =
inherit node
#
method name : Js.js_string Js.t Js.readonly_prop
#
method specified : bool Js.t Js.readonly_prop
#
method value : Js.js_string Js.t Js.prop
#
method ownerElement : element Js.t Js.prop

Specification of Attr objects.

#
class type ['node] namedNodeMap =
#
method getNamedItem : Js.js_string Js.t -> 'node Js.t Js.opt Js.meth
#
method setNamedItem : 'node Js.t -> 'node Js.t Js.opt Js.meth
#
method removeNamedItem : Js.js_string Js.t -> 'node Js.t Js.opt Js.meth
#
method item : int -> 'node Js.t Js.opt Js.meth
#
method length : int Js.readonly_prop

Specification of NamedNodeMap objects.

#
class type element =
inherit node
#
method tagName : Js.js_string Js.t Js.readonly_prop
#
method getAttribute : Js.js_string Js.t -> Js.js_string Js.t Js.opt Js.meth
#
method setAttribute : Js.js_string Js.t -> Js.js_string Js.t -> unit Js.meth
#
method removeAttribute : Js.js_string Js.t -> unit Js.meth
#
method hasAttribute : Js.js_string Js.t -> bool Js.t Js.meth
#
method getAttributeNS : Js.js_string Js.t -> Js.js_string Js.t -> Js.js_string Js.t Js.opt Js.meth
#
method setAttributeNS : Js.js_string Js.t -> Js.js_string Js.t -> Js.js_string Js.t -> unit Js.meth
#
method removeAttributeNS : Js.js_string Js.t -> Js.js_string Js.t -> unit Js.meth
#
method hasAttributeNS : Js.js_string Js.t -> Js.js_string Js.t -> bool Js.t Js.meth
#
method getAttributeNode : Js.js_string Js.t -> attr Js.t Js.opt Js.meth
#
method setAttributeNode : attr Js.t -> attr Js.t Js.opt Js.meth
#
method removeAttributeNode : attr Js.t -> attr Js.t Js.meth
#
method getAttributeNodeNS : Js.js_string Js.t -> Js.js_string Js.t -> attr Js.t Js.opt Js.meth
#
method setAttributeNodeNS : attr Js.t -> attr Js.t Js.opt Js.meth
#
method getElementsByTagName : Js.js_string Js.t -> element nodeList Js.t Js.meth
#
method attributes : attr namedNodeMap Js.t Js.readonly_prop

Specification of Element objects.

#
class type characterData =
inherit node
#
method data : Js.js_string Js.t Js.prop
#
method length : int Js.readonly_prop
#
method subjs_stringData : int -> int -> Js.js_string Js.t Js.meth
#
method appendData : Js.js_string Js.t -> unit Js.meth
#
method insertData : int -> Js.js_string Js.t -> unit Js.meth
#
method deleteData : int -> int -> unit Js.meth
#
method replaceData : int -> int -> Js.js_string Js.t -> unit Js.meth

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 =
inherit node
#
method documentElement : 'element Js.t Js.readonly_prop
#
method createDocumentFragment : documentFragment Js.t Js.meth
#
method createElement : Js.js_string Js.t -> 'element Js.t Js.meth
#
method createElementNS : Js.js_string Js.t -> Js.js_string Js.t -> 'element Js.t Js.meth
#
method createTextNode : Js.js_string Js.t -> text Js.t Js.meth
#
method createAttribute : Js.js_string Js.t -> attr Js.t Js.meth
#
method createComment : Js.js_string Js.t -> comment Js.t Js.meth
#
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
#
method importNode : element Js.t -> bool Js.t -> 'element Js.t Js.meth
#
method adoptNode : element Js.t -> 'element Js.t Js.meth

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 =
# | Element of element Js.t
# | Attr of attr Js.t
# | Text of text Js.t
# | Other of node Js.t
#
val nodeType : node Js.t -> node_type
#
module CoerceTo : sig
#
val element : node Js.t -> element Js.t Js.opt
#
val text : node Js.t -> text Js.t Js.opt
#
val attr : node Js.t -> attr Js.t Js.opt
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 =
#
method _type : Js.js_string Js.t Js.readonly_prop
#
method target : 'a Js.t Js.opt Js.readonly_prop
#
method currentTarget : 'a Js.t Js.opt Js.readonly_prop
#
method srcElement : 'a Js.t Js.opt Js.readonly_prop

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
#
type 'a typ
#
val make : string -> 'a typ
end
#
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 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.

Other DOM objects

#
class type stringList =
#
method item : int -> Js.js_string Js.t Js.opt Js.meth
#
method length : int Js.readonly_prop
#
method contains : Js.js_string Js.t -> bool Js.t Js.meth
end