class dom::Elem
sys::Obj dom::Elem
@Js
Elem models a DOM element object.
See pod doc for details.
- add
-
@Operator
virtual This add(Elem child)Add a new element as a child to this element. Return this.
- addAll
-
Add all elements to this element. Returns this.
- animateStart
-
Void animateStart(KeyFrames frames, [Str:Obj]? opts, Duration dur)Start an animation on this element using the given key frames.
frames := KeyFrames([ KeyFrame("0%", ["transform": "scale(1)"]), KeyFrame("50%", ["transform": "scale(1.1)"]), KeyFrame("100%", ["transform": "scale(1)"]), ]) animate(frames, null, 5sec) animate(frames, ["animation-iteration-count":"infinite"], 1sec) - animateStop
-
Void animateStop()Stop the current animation on this element, or do nothing if no animation in progress.
- attr
-
Get the given HTML attribute value for this element. Returns
nullif attribute not defined. - attrs
-
Get
name:valuemap of all attributes. - blur
-
virtual Void blur()Remove focus from this elem.
- children
-
Elem[] children()Get the child nodes of this element.
- clone
-
Return a duplicate of this node.
- closest
-
Traverses this element and its parents (heading toward the document root) until it finds a node that matches the specified CSS selector. Returns
nullif none found. - containsChild
-
Return
trueif given element is a descendant of this node, orfalseif not. - enabled
-
virtual Bool? enabledThe enabled attribute for this element, or null if one not applicable. This is typically only valid for form elements.
- firstChild
-
Elem? firstChild()Get the first child node of this element, or null if this element has no children.
- focus
-
virtual Void focus()Request keyboard focus on this elem.
- fromHtml
-
static Elem fromHtml(Str html)Create an
Eleminstance from a HTML string. This is equivlaentelem := Elem { it.html=html }.firstChild - fromNative
-
@Js
static Elem fromNative(Obj elem, Type type := dom::Elem#)Create an
Eleminstance from a native JavaScript DOM object. Thetypemay be specified to create a subclass instance of Elem. Note if the native instance has already been mapped to Fantom, the existing instance is returned andtypewill have no effect. - get
-
Convenience for
attr. - hasChildren
-
Bool hasChildren()Return
trueifchildrenis non-zero,falseotherwise. - hasFocus
-
virtual Bool hasFocus()Return true if this elem has focus.
- html
-
Str htmlThe HTML markup contained in this element.
- id
-
Str? idThe id for this element. Returns
nullif id is not defined. - insertBefore
-
virtual This insertBefore(Elem child, Elem ref)Insert a new element as a child to this element before the specified reference element. The reference element must be a child of this element. Returns this.
- invoke
-
Obj? invoke(Str name, Obj?[]? args := null)Invoke the given native DOM function with optional arguments.
- lastChild
-
Elem? lastChild()Get the last child node of this element, or null if this element has no children.
- make
-
new make(Str tagName := "div", Uri? ns := null)Create a new Elem in the current Doc. Optionally a namespace can be specified with
ns. - nextSibling
-
Elem? nextSibling()Get the next sibling to this element, or null if this is the last element under its parent.
- ns
-
Uri ns()The namespace URI of this element.
- onEvent
-
Func onEvent(Str type, Bool useCapture, |Event| handler)Attach an event handler for the given event on this element. Returns callback function instance.
- pagePos
-
Point pagePos()Position of element relative to the whole document.
- parent
-
Elem? parent()Get the parent Elem of this element, or null if this element has no parent.
- pos
-
Point posPosition of element relative to its parent in pixels.
- prevSibling
-
Elem? prevSibling()Get the previous sibling to this element, or null if this is the first element under its parent.
- prop
-
Get the given DOM property value for this element. Returns
nullif property does not exist. - querySelector
-
Elem? querySelector(Str selectors)Returns the first element that is a descendant of this element on which it is invoked that matches the specified group of selectors.
- querySelectorAll
-
Elem[] querySelectorAll(Str selectors)Returns a list of all elements descended from this element on which it is invoked that match the specified group of CSS selectors.
- relPos
-
Given a page position, return
prelative to this element. - remove
-
virtual This remove(Elem child)Remove a child element from this element. Return this.
- removeAll
-
This removeAll()Remove all children from this element. Returns this.
- removeAttr
-
Remove the given HTML attribute from this element.
- removeEvent
-
Void removeEvent(Str type, Bool useCapture, Func handler)Remove the given event handler from this element. If this handler was not registered, this method does nothing.
- renderCanvas
-
Void renderCanvas(|Graphics| f)Paint a
<canvas>element. The given callback is invoked with a graphics context to perform the rendering operation. Before calling this code, you should set the canvas width/height attributes to match the element size (typically as a ratio of the Win.devicePixelRatio). - replace
-
virtual This replace(Elem oldChild, Elem newChild)Replace existing child node with a new child. Returns this.
- scrollIntoView
-
This scrollIntoView(Bool alignToTop := true)Scroll parent container so this Elem is visible to user. If
alignToTopistrue(the default value), the top of Elem is aligned to top of the visible area. Iffalse, the bottom of Elem is aligned to bottom of the visible area. - scrollPos
-
Point scrollPosTop left scroll position of element.
- scrollSize
-
Size scrollSize()Scrollable size of element.
- set
-
@Operator
Void set(Str name, Str? val)Conveneince for
setAttr. - setAttr
-
This setAttr(Str name, Str? val, Uri? ns := null)Set the given HTML attribute value for this element. If
valisnullthe attribute is removed (seeremoveAttr). Optionally a namespace can be specified withns. - setProp
-
This setProp(Str name, Obj? val)Set the given DOM properity value for this element.
- size
-
Size sizeSize of element in pixels.
- style
-
Style style()Get the Style instance for this element.
- tagName
-
Str tagName()Get the tag name for this element.
- text
-
Str textText content contained in this element.
- transition
-
Void transition(Str:Obj props, [Str:Obj]? opts, Duration dur, |Elem|? onComplete := null)Transition a set of CSS properties.
transition(["opacity": "0.5"], null, 1sec) { echo("done!") } transition(["opacity": "0.5"], ["transition-delay": 500ms], 1sec) { echo("done!") } - trap
-
virtual override Obj? trap(Str name, Obj?[]? args := null)The
trapoperator will behave slightly differently based on the namespace of the element.For HTML elements,
trapworks as a convenience forpropandsetProp:div := Elem("div") div->tabIndex = 0 // equivalent to div.setProp("tabIndex", 0)For SVG elements (where
nsis`http://www.w3.org/2000/svg`),traproutes toattrandsetAttr:svg := Svg.line(0, 0, 10, 10) svg->x1 = 5 // equivalent to svg.setAttr("x1", "5") svg->y1 = 5 // equivalent to svg.setAttr("y1", "5") svg->x2 == "10" // equivalent to svg.attr("x2")