Module Js_of_ocaml__.Dom_html

CSS style declaration

class type cssStyleDeclaration = object ... end

Events

type (-'a, -'b) event_listener = ('a'b) Js_of_ocaml.Dom.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.

type mouse_button =
| No_button
| Left_button
| Middle_button
| Right_button
class type event = object ... end
and 'a customEvent = object ... end
and focusEvent = object ... end
and mouseEvent = object ... end
and keyboardEvent = object ... end
and mousewheelEvent = object ... end
and mouseScrollEvent = object ... end
and touchEvent = object ... end
and touchList = object ... end
and touch = object ... end
and dragEvent = object ... end
and dataTransfer = object ... end
and eventTarget = object ... end

Common properties of event target objects: onclick, onkeypress, ...

and popStateEvent = object ... end
and pointerEvent = object ... end
and storageEvent = object ... end
and storage = object ... end

Storage

and hashChangeEvent = object ... end
and animationEvent = object ... end
and mediaEvent = object ... end

HTML elements

and nodeSelector = object ... end
and tokenList = object ... end
and element = object ... end

Properties common to all HTML elements

and clientRect = object ... end

Rectangular box (used for element bounding boxes)

and clientRectList = object ... end
class type 'node collection = object ... end

Collection of HTML elements

class type htmlElement = element
class type headElement = object ... end
class type linkElement = object ... end
class type titleElement = object ... end
class type metaElement = object ... end
class type baseElement = object ... end
class type styleElement = object ... end
class type bodyElement = element
class type formElement = object ... end
class type optGroupElement = object ... end
class type optionElement = object ... end
class type selectElement = object ... end
class type inputElement = object ... end
class type textAreaElement = object ... end
class type buttonElement = object ... end
class type labelElement = object ... end
class type fieldSetElement = object ... end
class type legendElement = object ... end
class type uListElement = element
class type oListElement = element
class type dListElement = element
class type liElement = element
class type divElement = element
class type headingElement = element
class type quoteElement = object ... end
class type preElement = element
class type brElement = element
class type hrElement = element
class type modElement = object ... end
class type anchorElement = object ... end
class type imageElement = object ... end
class type objectElement = object ... end
class type paramElement = object ... end
class type areaElement = object ... end
class type mapElement = object ... end
class type scriptElement = object ... end
class type embedElement = object ... end
class type tableCellElement = object ... end
class type tableRowElement = object ... end
class type tableColElement = object ... end
class type tableSectionElement = object ... end
class type tableElement = object ... end
class type timeRanges = object ... end
type networkState =
| NETWORK_EMPTY
| NETWORK_IDLE
| NETWORK_LOADING
| NETWORK_NO_SOURCE
type readyState =
| HAVE_NOTHING
| HAVE_METADATA
| HAVE_CURRENT_DATA
| HAVE_FUTURE_DATA
| HAVE_ENOUGH_DATA
class type mediaElement = object ... end
class type audioElement = object ... end
class type videoElement = object ... end

Canvas object

type context
val _2d_ : context
type canvasPattern
class type canvasElement = object ... end
and canvasRenderingContext2D = object ... end
and canvasGradient = object ... end
and textMetrics = object ... end
and imageData = object ... end
and canvasPixelArray = object ... end
val pixel_get : canvasPixelArray Js_of_ocaml.Js.t -> int -> int
val pixel_set : canvasPixelArray Js_of_ocaml.Js.t -> int -> int -> unit
class type range = object ... end

Object representing a range *

class type selection = object ... end

Information on current selection

Document objects

class type document = object ... end
val document : document Js_of_ocaml.Js.t

The current document

val getElementById_opt : string -> element Js_of_ocaml.Js.t option

getElementById_opt id returns the element with the id id in the current document. It returns None if there are no such element

val getElementById_exn : string -> element Js_of_ocaml.Js.t

getElementById_exn id returns the element with the id id in the current document. It raises if there are no such element

val getElementById_coerce : string -> (element Js_of_ocaml.Js.t -> 'a Js_of_ocaml.Js.opt) -> 'a option

getElementById_coerce id coerce returns the element with the id id in the current document and attempt to coerce it using the provided coerce function. It returns None if there are no such element or if the coerce function returns Js.none. Typical usage is the following:

match Dom_html.getElementById_coerce "myinput" Dom_html.CoerceTo.input with
| None -> ..
| Some input -> ..
val getElementById : string -> element Js_of_ocaml.Js.t

getElementById id returns the element with the id id in the current document. It raises Not_found if there are no such element

Window objects

class type location = object ... end

Location information

val location_origin : location Js_of_ocaml.Js.t -> Js_of_ocaml.Js.js_string Js_of_ocaml.Js.t
class type history = object ... end

Browser history information

class type undoManager = object ... end

Undo manager

class type navigator = object ... end

Navigator information

class type screen = object ... end
class type applicationCache = object ... end
type interval_id
type timeout_id
type animation_frame_request_id
class type _URL = object ... end
class type window = object ... end

Specification of window objects

val window : window Js_of_ocaml.Js.t

The current window

class type frameSetElement = object ... end
class type frameElement = object ... end
class type iFrameElement = object ... end

Event handlers

val no_handler : ('a'b) event_listener

see Dom.no_handler

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

see Dom.handler

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

see Dom.full_handler

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

see Dom.invoke_handler

val eventTarget : event Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t

see Dom.eventTarget

val eventRelatedTarget : mouseEvent Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t Js_of_ocaml.Js.opt

Returns this event related target.

module Event : sig ... end

Event types: mousedown, keypress, ...

type event_listener_id = Js_of_ocaml.Dom.event_listener_id
val addEventListenerWithOptions : eventTarget Js_of_ocaml.Js.t as 'a -> 'b Event.typ -> ?⁠capture:bool Js_of_ocaml.Js.t -> ?⁠once:bool Js_of_ocaml.Js.t -> ?⁠passive:bool Js_of_ocaml.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 : eventTarget Js_of_ocaml.Js.t as 'a -> 'b Event.typ -> ('a'b) event_listener -> bool Js_of_ocaml.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 addMousewheelEventListenerWithOptions : eventTarget Js_of_ocaml.Js.t as 'a -> ?⁠capture:bool Js_of_ocaml.Js.t -> ?⁠once:bool Js_of_ocaml.Js.t -> ?⁠passive:bool Js_of_ocaml.Js.t -> (mouseEvent Js_of_ocaml.Js.t -> dx:int -> dy:int -> bool Js_of_ocaml.Js.t) -> event_listener_id

Add a mousewheel event listener with option-object variant of the addEventListener DOM method. The callback is provided the event and the numbers of ticks the mouse wheel moved. Positive means down / right.

val addMousewheelEventListener : eventTarget Js_of_ocaml.Js.t as 'a -> (mouseEvent Js_of_ocaml.Js.t -> dx:int -> dy:int -> bool Js_of_ocaml.Js.t) -> bool Js_of_ocaml.Js.t -> event_listener_id

Add a mousewheel event listener with the useCapture boolean variant of the addEventListener DOM method. The callback is provided the event and the numbers of ticks the mouse wheel moved. Positive means down / right.

val createCustomEvent : ?⁠bubbles:bool -> ?⁠cancelable:bool -> ?⁠detail:'a -> 'a customEvent Js_of_ocaml.Js.t Event.typ -> 'a customEvent Js_of_ocaml.Js.t

See Dom.createCustomEvent

Mouse event helper functions

val buttonPressed : mouseEvent Js_of_ocaml.Js.t -> mouse_button

Position helper functions

val eventAbsolutePosition : mouseEvent Js_of_ocaml.Js.t -> int * int

Returns the absolute position of the mouse pointer.

val elementClientPosition : element Js_of_ocaml.Js.t -> int * int

Position of an element relative to the viewport

val getDocumentScroll : unit -> int * int

Viewport top/left position

Key event helper functions

module Keyboard_code : sig ... end

Use Keyboard_code when you want to identify a key that the user pressed. This should be invoked for keydown and keyup events, not keypress events.

module Keyboard_key : sig ... end

Use Keyboard_key when you want to identify the character that the user typed. This should only be invoked on keypress events, not keydown or keyup events.

Helper functions for creating HTML elements

val createHtml : document Js_of_ocaml.Js.t -> htmlElement Js_of_ocaml.Js.t
val createHead : document Js_of_ocaml.Js.t -> headElement Js_of_ocaml.Js.t
val createTitle : document Js_of_ocaml.Js.t -> titleElement Js_of_ocaml.Js.t
val createMeta : document Js_of_ocaml.Js.t -> metaElement Js_of_ocaml.Js.t
val createBase : document Js_of_ocaml.Js.t -> baseElement Js_of_ocaml.Js.t
val createStyle : document Js_of_ocaml.Js.t -> styleElement Js_of_ocaml.Js.t
val createBody : document Js_of_ocaml.Js.t -> bodyElement Js_of_ocaml.Js.t
val createForm : document Js_of_ocaml.Js.t -> formElement Js_of_ocaml.Js.t
val createOptgroup : document Js_of_ocaml.Js.t -> optGroupElement Js_of_ocaml.Js.t
val createOption : document Js_of_ocaml.Js.t -> optionElement Js_of_ocaml.Js.t
val createSelect : ?⁠_type:Js_of_ocaml.Js.js_string Js_of_ocaml.Js.t -> ?⁠name:Js_of_ocaml.Js.js_string Js_of_ocaml.Js.t -> document Js_of_ocaml.Js.t -> selectElement Js_of_ocaml.Js.t
val createInput : ?⁠_type:Js_of_ocaml.Js.js_string Js_of_ocaml.Js.t -> ?⁠name:Js_of_ocaml.Js.js_string Js_of_ocaml.Js.t -> document Js_of_ocaml.Js.t -> inputElement Js_of_ocaml.Js.t
val createTextarea : ?⁠_type:Js_of_ocaml.Js.js_string Js_of_ocaml.Js.t -> ?⁠name:Js_of_ocaml.Js.js_string Js_of_ocaml.Js.t -> document Js_of_ocaml.Js.t -> textAreaElement Js_of_ocaml.Js.t
val createButton : ?⁠_type:Js_of_ocaml.Js.js_string Js_of_ocaml.Js.t -> ?⁠name:Js_of_ocaml.Js.js_string Js_of_ocaml.Js.t -> document Js_of_ocaml.Js.t -> buttonElement Js_of_ocaml.Js.t
val createLabel : document Js_of_ocaml.Js.t -> labelElement Js_of_ocaml.Js.t
val createFieldset : document Js_of_ocaml.Js.t -> fieldSetElement Js_of_ocaml.Js.t
val createLegend : document Js_of_ocaml.Js.t -> legendElement Js_of_ocaml.Js.t
val createUl : document Js_of_ocaml.Js.t -> uListElement Js_of_ocaml.Js.t
val createOl : document Js_of_ocaml.Js.t -> oListElement Js_of_ocaml.Js.t
val createDl : document Js_of_ocaml.Js.t -> dListElement Js_of_ocaml.Js.t
val createLi : document Js_of_ocaml.Js.t -> liElement Js_of_ocaml.Js.t
val createDiv : document Js_of_ocaml.Js.t -> divElement Js_of_ocaml.Js.t
val createEmbed : document Js_of_ocaml.Js.t -> embedElement Js_of_ocaml.Js.t
val createP : document Js_of_ocaml.Js.t -> paragraphElement Js_of_ocaml.Js.t
val createH1 : document Js_of_ocaml.Js.t -> headingElement Js_of_ocaml.Js.t
val createH2 : document Js_of_ocaml.Js.t -> headingElement Js_of_ocaml.Js.t
val createH3 : document Js_of_ocaml.Js.t -> headingElement Js_of_ocaml.Js.t
val createH4 : document Js_of_ocaml.Js.t -> headingElement Js_of_ocaml.Js.t
val createH5 : document Js_of_ocaml.Js.t -> headingElement Js_of_ocaml.Js.t
val createH6 : document Js_of_ocaml.Js.t -> headingElement Js_of_ocaml.Js.t
val createQ : document Js_of_ocaml.Js.t -> quoteElement Js_of_ocaml.Js.t
val createBlockquote : document Js_of_ocaml.Js.t -> quoteElement Js_of_ocaml.Js.t
val createPre : document Js_of_ocaml.Js.t -> preElement Js_of_ocaml.Js.t
val createBr : document Js_of_ocaml.Js.t -> brElement Js_of_ocaml.Js.t
val createHr : document Js_of_ocaml.Js.t -> hrElement Js_of_ocaml.Js.t
val createIns : document Js_of_ocaml.Js.t -> modElement Js_of_ocaml.Js.t
val createDel : document Js_of_ocaml.Js.t -> modElement Js_of_ocaml.Js.t
val createA : document Js_of_ocaml.Js.t -> anchorElement Js_of_ocaml.Js.t
val createImg : document Js_of_ocaml.Js.t -> imageElement Js_of_ocaml.Js.t
val createObject : document Js_of_ocaml.Js.t -> objectElement Js_of_ocaml.Js.t
val createParam : document Js_of_ocaml.Js.t -> paramElement Js_of_ocaml.Js.t
val createMap : document Js_of_ocaml.Js.t -> mapElement Js_of_ocaml.Js.t
val createArea : document Js_of_ocaml.Js.t -> areaElement Js_of_ocaml.Js.t
val createScript : document Js_of_ocaml.Js.t -> scriptElement Js_of_ocaml.Js.t
val createTable : document Js_of_ocaml.Js.t -> tableElement Js_of_ocaml.Js.t
val createCaption : document Js_of_ocaml.Js.t -> tableCaptionElement Js_of_ocaml.Js.t
val createCol : document Js_of_ocaml.Js.t -> tableColElement Js_of_ocaml.Js.t
val createColgroup : document Js_of_ocaml.Js.t -> tableColElement Js_of_ocaml.Js.t
val createThead : document Js_of_ocaml.Js.t -> tableSectionElement Js_of_ocaml.Js.t
val createTfoot : document Js_of_ocaml.Js.t -> tableSectionElement Js_of_ocaml.Js.t
val createTbody : document Js_of_ocaml.Js.t -> tableSectionElement Js_of_ocaml.Js.t
val createTr : document Js_of_ocaml.Js.t -> tableRowElement Js_of_ocaml.Js.t
val createTh : document Js_of_ocaml.Js.t -> tableCellElement Js_of_ocaml.Js.t
val createTd : document Js_of_ocaml.Js.t -> tableCellElement Js_of_ocaml.Js.t
val createSub : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createSup : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createSpan : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createTt : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createI : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createB : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createBig : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createSmall : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createEm : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createStrong : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createCite : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createDfn : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createCode : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createSamp : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createKbd : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createVar : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createAbbr : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createDd : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createDt : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createNoscript : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createAddress : document Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t
val createFrameset : document Js_of_ocaml.Js.t -> frameSetElement Js_of_ocaml.Js.t
val createFrame : document Js_of_ocaml.Js.t -> frameElement Js_of_ocaml.Js.t
val createIframe : document Js_of_ocaml.Js.t -> iFrameElement Js_of_ocaml.Js.t
val createAudio : document Js_of_ocaml.Js.t -> audioElement Js_of_ocaml.Js.t
val createVideo : document Js_of_ocaml.Js.t -> videoElement Js_of_ocaml.Js.t
exception Canvas_not_available
val createCanvas : document Js_of_ocaml.Js.t -> canvasElement Js_of_ocaml.Js.t
raises Canvas_not_available

when canvas elements are not supported by the browser.

Coercion functions

val element : Js_of_ocaml__.Dom.#element Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t

Coercion from a general DOM element to an HTML element. (Unsafe in general.)

type taggedElement =
| A of anchorElement Js_of_ocaml.Js.t
| Area of areaElement Js_of_ocaml.Js.t
| Audio of audioElement Js_of_ocaml.Js.t
| Base of baseElement Js_of_ocaml.Js.t
| Blockquote of quoteElement Js_of_ocaml.Js.t
| Body of bodyElement Js_of_ocaml.Js.t
| Br of brElement Js_of_ocaml.Js.t
| Button of buttonElement Js_of_ocaml.Js.t
| Canvas of canvasElement Js_of_ocaml.Js.t
| Caption of tableCaptionElement Js_of_ocaml.Js.t
| Col of tableColElement Js_of_ocaml.Js.t
| Colgroup of tableColElement Js_of_ocaml.Js.t
| Del of modElement Js_of_ocaml.Js.t
| Div of divElement Js_of_ocaml.Js.t
| Dl of dListElement Js_of_ocaml.Js.t
| Embed of embedElement Js_of_ocaml.Js.t
| Fieldset of fieldSetElement Js_of_ocaml.Js.t
| Form of formElement Js_of_ocaml.Js.t
| Frameset of frameSetElement Js_of_ocaml.Js.t
| Frame of frameElement Js_of_ocaml.Js.t
| H1 of headingElement Js_of_ocaml.Js.t
| H2 of headingElement Js_of_ocaml.Js.t
| H3 of headingElement Js_of_ocaml.Js.t
| H4 of headingElement Js_of_ocaml.Js.t
| H5 of headingElement Js_of_ocaml.Js.t
| H6 of headingElement Js_of_ocaml.Js.t
| Head of headElement Js_of_ocaml.Js.t
| Hr of hrElement Js_of_ocaml.Js.t
| Html of htmlElement Js_of_ocaml.Js.t
| Iframe of iFrameElement Js_of_ocaml.Js.t
| Img of imageElement Js_of_ocaml.Js.t
| Input of inputElement Js_of_ocaml.Js.t
| Ins of modElement Js_of_ocaml.Js.t
| Label of labelElement Js_of_ocaml.Js.t
| Legend of legendElement Js_of_ocaml.Js.t
| Li of liElement Js_of_ocaml.Js.t
| Map of mapElement Js_of_ocaml.Js.t
| Meta of metaElement Js_of_ocaml.Js.t
| Object of objectElement Js_of_ocaml.Js.t
| Ol of oListElement Js_of_ocaml.Js.t
| Optgroup of optGroupElement Js_of_ocaml.Js.t
| Option of optionElement Js_of_ocaml.Js.t
| P of paramElement Js_of_ocaml.Js.t
| Param of paramElement Js_of_ocaml.Js.t
| Pre of preElement Js_of_ocaml.Js.t
| Q of quoteElement Js_of_ocaml.Js.t
| Script of scriptElement Js_of_ocaml.Js.t
| Select of selectElement Js_of_ocaml.Js.t
| Style of styleElement Js_of_ocaml.Js.t
| Table of tableElement Js_of_ocaml.Js.t
| Tbody of tableSectionElement Js_of_ocaml.Js.t
| Td of tableCellElement Js_of_ocaml.Js.t
| Textarea of textAreaElement Js_of_ocaml.Js.t
| Tfoot of tableSectionElement Js_of_ocaml.Js.t
| Th of tableCellElement Js_of_ocaml.Js.t
| Thead of tableSectionElement Js_of_ocaml.Js.t
| Title of titleElement Js_of_ocaml.Js.t
| Tr of tableRowElement Js_of_ocaml.Js.t
| Ul of uListElement Js_of_ocaml.Js.t
| Video of videoElement Js_of_ocaml.Js.t
| Other of element Js_of_ocaml.Js.t
val tagged : element Js_of_ocaml.Js.t -> taggedElement
val opt_tagged : element Js_of_ocaml.Js.t Js_of_ocaml.Js.opt -> taggedElement option
type taggedEvent =
| MouseEvent of mouseEvent Js_of_ocaml.Js.t
| KeyboardEvent of keyboardEvent Js_of_ocaml.Js.t
| MousewheelEvent of mousewheelEvent Js_of_ocaml.Js.t
| MouseScrollEvent of mouseScrollEvent Js_of_ocaml.Js.t
| PopStateEvent of popStateEvent Js_of_ocaml.Js.t
| OtherEvent of event Js_of_ocaml.Js.t
val taggedEvent : event Js_of_ocaml.Js.t -> taggedEvent
val opt_taggedEvent : event Js_of_ocaml.Js.t Js_of_ocaml.Js.opt -> taggedEvent option
val stopPropagation : event Js_of_ocaml.Js.t -> unit
module CoerceTo : sig ... end
type timeout_id_safe
val setTimeout : (unit -> unit) -> float -> timeout_id_safe

Same as Dom_html.window##setTimeout cb ms but prevents overflow with delay greater than 24 days.

val clearTimeout : timeout_id_safe -> unit
val js_array_of_collection : element collection Js_of_ocaml.Js.t -> element Js_of_ocaml.Js.t Js_of_ocaml.Js.js_array Js_of_ocaml.Js.t

Convert a Dom_html.collection to a Js array

Deprecated function.

val _requestAnimationFrame : (unit -> unit) Js_of_ocaml.Js.callback -> unit

Call the appropriate requestAnimationFrame method variant (depending on the navigator), or sleep for a short amount of time when there no such method is provided. We currently prefix the function name with as underscore as the interface of this function is not completely standardized yet. Thus, we leave the room to a function with a possibly refined type.

This function is deprecated. Use the requestAnimationFrame of the window object instead.