wrld.js

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.

Functions

Function Returns Description
get(<String|HTMLElement> id) HTMLElement Returns an element given its DOM id, or returns the element itself if it was passed directly.
getStyle(<HTMLElement> el, <String> styleAttrib) String Returns the value for a certain style attribute on an element, including computed values or values set through CSS.
create(<String> tagName, <String> className?, <HTMLElement> container?) HTMLElement Creates an HTML element with tagName, sets its class to className, and optionally appends it to container element.
remove(<HTMLElement> el) Removes el from its parent element
empty(<HTMLElement> el) Removes all of el's children elements from el
toFront(<HTMLElement> el) Makes el the last children of its parent, so it renders in front of the other children.
toBack(<HTMLElement> el) Makes el the first children of its parent, so it renders back from the other children.
hasClass(<HTMLElement> el, <String> name) Boolean Returns true if the element's class attribute contains name.
addClass(<HTMLElement> el, <String> name) Adds name to the element's class attribute.
removeClass(<HTMLElement> el, <String> name) Removes name from the element's class attribute.
setClass(<HTMLElement> el, <String> name) Sets the element's class.
getClass(<HTMLElement> el) String Returns the element's class.
setOpacity(<HTMLElement> el, <Number> opacity) Set the opacity of an element (including old IE support). opacity must be a number from 0 to 1.
testProp(<String[]> props) String|false Goes through the array of style names and returns the first name that is a valid style name for an element. If no such name is found, it returns false. Useful for vendor-prefixed styles like transform.
setTransform(<HTMLElement> el, <Point> offset, <Number> scale?) Resets the 3D CSS transform of el so it is translated by offset pixels and optionally scaled by scale. Does not have an effect if the browser doesn't support 3D CSS transforms.
setPosition(<HTMLElement> el, <Point> position) Sets the position of el to coordinates specified by position, using CSS translate or top/left positioning depending on the browser (used by Leaflet internally to position its layers).
getPosition(<HTMLElement> el) Point Returns the coordinates of an element previously positioned with setPosition.
disableTextSelection() Prevents the user from generating selectstart DOM events, usually generated when the user drags the mouse through a page with text. Used internally by Leaflet to override the behaviour of any click-and-drag interaction on the map. Affects drag interactions on the whole document.
enableTextSelection() Cancels the effects of a previous L.DomUtil.disableTextSelection.
disableImageDrag() As L.DomUtil.disableTextSelection, but for dragstart DOM events, usually generated when the user drags an image.
enableImageDrag() Cancels the effects of a previous L.DomUtil.disableImageDrag.
preventOutline(<HTMLElement> el) Makes the outline of the element el invisible. Used internally by Leaflet to prevent focusable elements from displaying an outline when the user performs a drag interaction on them.
restoreOutline() Cancels the effects of a previous L.DomUtil.preventOutline.

Properties

Property Type Description
TRANSFORM String Vendor-prefixed fransform style name (e.g. 'webkitTransform' for WebKit).
TRANSITION String Vendor-prefixed transform style name.
v0.1.1452