Skip to content

DomUtil

@namespace DomUtil

Utility functions to work with the DOM tree, used by Leaflet internally.

Most functions expecting or returning a HTMLElement also work for SVG elements. The only difference is that classes refer to CSS classes in HTML and SVG classes in SVG.

Methods

MethodReturnsDescription
`get(id: StringHTMLElement)`HTMLElement
create(tagName: String, className?: String, container?: HTMLElement)HTMLElementCreates an HTML element with tagName, sets its class to className, and optionally appends it to container element.
toFront(el: HTMLElement)Makes el the last child of its parent, so it renders in front of the other children.
toBack(el: HTMLElement)Makes el the first child of its parent, so it renders behind the other children.
setTransform(el: HTMLElement, offset: Point, scale?: Number)Resets the 3D CSS transform of el so it is translated by offset pixels
setPosition(el: HTMLElement, position: Point)Sets the position of el to coordinates specified by position,
getPosition(el: HTMLElement)PointReturns the coordinates of an element previously positioned with setPosition.
disableTextSelection()Prevents the user from selecting text in the document. Used internally
enableTextSelection()Cancels the effects of a previous DomUtil.disableTextSelection.
disableImageDrag()Prevents the user from generating dragstart DOM events, usually generated when the user drags an image.
enableImageDrag()Cancels the effects of a previous DomUtil.disableImageDrag.
preventOutline(el: HTMLElement)Makes the outline
restoreOutline()Cancels the effects of a previous DomUtil.preventOutline.
getSizedParentNode(el: HTMLElement)HTMLElementFinds the closest parent node which size (width and height) is not null.
getScale(el: HTMLElement)ObjectComputes the CSS scale currently applied on the element.