Interface Element
- All Superinterfaces:
 DomQueryable,EventTarget,Node
- All Known Subinterfaces:
 BodyElement,ButtonElement,CanvasElement,ComponentElement,DelphiElement,HeadElement,InputElement,ItemElement,JavaObjectElement,OptionElement,ScriptElement,StyleElement
 Elements are not guaranteed to have children. An element can only support children if
 canHaveChildren() returns true.
- See Also:
 
- 
Method Summary
Modifier and TypeMethodDescriptionvoidappendChild(@NotNull Node node) Adds a child node to the end of this element's child nodes.default @NotNull ElementappendElement(@NotNull String tagName) Appends an element and returns it.default @NotNull TextNodeappendText(@Nullable String text) Creates a text node and appends it to this elementbooleanTests if this element is capable of having child nodes.voidRemove all child elements.@Nullable NodeGets the first child of this element.voidforEachDescendant(@NotNull Consumer<Node> consumer) Applies a consumer to all descendant nodes of this element.@Nullable StringgetAttribute(String key) Gets the value of an attribute.Gets a set of attribute entries that exist on this element.Get a set of attribute keys that exist on this element.getChild(int index) Gets the nth child of this element.intGets the amount of children the element hasGets an immutable list of child nodesGets the element's class array list.default @Nullable StringGets the element'sAttributes.CLASSattribute value.Get the element's current style.default StringgetId()Shorthand for getting the id attribute's valuegetStyle()Get the modifiable inline style properties.Gets the element's tag name.Get the element's text content.@Nullable ElementGets the element's title node.@Nullable NodeGets the element's tooltip.@NotNull TooltipBehaviourGet the tooltip behaviour.longGet the tooltip appearance delay in ticks.booleanhasAttribute(@Nullable String key) Test if the element has an attribute with a mapped value.booleanTests if the specifiednodeis a direct child of this elementbooleanTests if this element has children.intGets the index of a node that is the direct child of this element.voidinsertAfter(@NotNull Node node, @NotNull Node after) Inserts an element after the specified nodevoidinsertBefore(@NotNull Node node, @NotNull Node before) Inserts an element before the specified nodebooleanisDescendant(@Nullable Node node) Test if a specifiednodeis a descendant of the element.@Nullable NodeGets the last child of this element.booleanTest if the element matches a CSS selector.voidprependChild(@NotNull Node node) Adds a child node to start of this element's child nodes.@Nullable StringremoveAttribute(String attributeName) Remove an attribute.voidremoveChild(int childIndex) Removes a child element by its index.booleanremoveChild(@NotNull Node node) Removes a specified child from this element.voidremoveMatchingChildren(@NotNull Predicate<Node> filter) Remove all child nodes that match the specifiedfilterpredicate.voidreplaceChild(int idx, @NotNull Node node) Replace a child element at the specified index.voidreplaceChild(@NotNull Node child, @NotNull Node node) Replace a child element at the specified index.voidsetAttribute(@NotNull String key, @Nullable String value) Sets an attribute's value.default voidsetClassName(String className) Sets the element'sAttributes.CLASSattribute valuedefault voidShorthand for setting the id attributevoidsetTextContent(String content) Remove all child elements and replace it with the specifiedcontentvoidsetTitleNode(@Nullable Element title) Sets the element's title node.voidsetTooltipBehaviour(@Nullable TooltipBehaviour mode) Set the tooltip behaviour.voidsetTooltipDelay(@Nullable String timeString) Set the tooltip appearance delay in ticks.Methods inherited from interface com.juliewoolie.dom.DomQueryable
getElementsByClassName, getElementsByTagName, querySelector, querySelectorAllMethods inherited from interface com.juliewoolie.dom.event.EventTarget
addEventListener, dispatchEvent, getOnAddAttribute, getOnAddOption, getOnAppendChild, getOnAttributeChange, getOnClick, getOnClosing, getOnInput, getOnLoaded, getOnMouseEnter, getOnMouseExit, getOnMouseMove, getOnOptionChange, getOnRemoveAttribute, getOnRemoveChild, getOnRemoveOption, getOnRightClick, getOnSetAttribute, getOnSetOption, getOnSpawned, onAddAttribute, onAddOption, onAppendChild, onAttributeChange, onClick, onClosing, onInput, onLoaded, onMouseEnter, onMouseExit, onMouseMove, onOptionChange, onRemoveAttribute, onRemoveChild, onRemoveOption, onRightClick, onSetAttribute, onSetOption, onSpawned, removeEventListenerMethods inherited from interface com.juliewoolie.dom.Node
enterVisitor, exitVisitor, getDepth, getOwningDocument, getParent, getRenderingBounds, getSiblingIndex, hasFlag, nextSibling, previousSibling 
- 
Method Details
- 
getStyle
StyleProperties getStyle()Get the modifiable inline style properties.Any changes made to the returned properties will be reflected in the
Attributes.STYLEattribute, and any changes to theAttributes.STYLEattribute will be reflected in the returned properties.- Returns:
 - Inline style
 
 - 
getCurrentStyle
StylePropertiesReadonly getCurrentStyle()Get the element's current style.The returned result's properties will be the computed style values of all applicable stylesheet rules and the inline style for the element.
- Returns:
 - Unmodifiable style properties
 
 - 
getAttribute
 - 
hasAttribute
Test if the element has an attribute with a mapped value.- Parameters:
 key- Attribute name- Returns:
 true, if the element has a value mapped for the specified attribute,falseotherwise.
 - 
setAttribute
Sets an attribute's value.If the specified
valueis already set as the value for this attribute, nothing will change.
Otherwise, anEventTypes.MODIFY_ATTRevent will be triggered after the value is set.- Parameters:
 key- Attribute keyvalue- Attribute value, ornullto remove.- Throws:
 NullPointerException- ifkeyisnullor empty
 - 
removeAttribute
Remove an attribute.If the specified attribute isn't set for this attribute, nothing will change.
Otherwise, anEventTypes.MODIFY_ATTRevent will be triggered after the attribute is removed- Parameters:
 attributeName- Attribute name- Returns:
 - The attribute's value before being removed
 - Throws:
 NullPointerException- ifattributeNameisnullor empty
 - 
getAttributeNames
 - 
getAttributeEntries
 - 
getId
 - 
setId
Shorthand for setting the id attribute- Parameters:
 elementId- Element ID- See Also:
 
 - 
getClassName
Gets the element'sAttributes.CLASSattribute value.- Returns:
 - Class name
 
 - 
setClassName
Sets the element'sAttributes.CLASSattribute value- Parameters:
 className- Class name
 - 
getClassList
Gets the element's class array list.Any modifications made to the returned array will be reflected in the element's
classattribute andgetCurrentStyle()- Returns:
 - An array list containing all the classes of this element.
 
 - 
getTagName
 - 
getTooltip
 - 
getTitleNode
Gets the element's title node.The title node is used as the element's hover tooltip.
- Returns:
 - Title node
 
 - 
setTitleNode
Sets the element's title node.The title node is used as the element's hover tooltip.
- Parameters:
 title- Title node
 - 
getTooltipDelay
long getTooltipDelay()Get the tooltip appearance delay in ticks.Shorthand for accessing the
Attributes.TOOLTIP_DELAYattribute's parsed value.If the attribute cannot be parsed, wasn't set, or an unknown time unit was used, this method defaults to
0.- Returns:
 - Tooltip delay in ticks.
 - See Also:
 
 - 
setTooltipDelay
Set the tooltip appearance delay in ticks.Shorthand for modifying the
Attributes.TOOLTIP_DELAYattribute value.- Parameters:
 timeString- Tooltip delay, ornull, to remove the attribute.- See Also:
 
 - 
getTooltipBehaviour
Get the tooltip behaviour.Shorthand for accessing the
Attributes.TOOLTIP_BEHAVIOURattribute's parsed value.If the value of the attribute couldn't be parsed or wasn't set, then
TooltipBehaviour.CURSOR_STICKYis returned.- Returns:
 - Tooltip behaviour
 - See Also:
 
 - 
setTooltipBehaviour
Set the tooltip behaviour.Shorthand for modifying the
Attributes.TOOLTIP_BEHAVIOURattribute's value.- Parameters:
 mode- Tooltip behaviour, ornull, to remove the attribute's value
 - 
appendChild
Adds a child node to the end of this element's child nodes.If the specified
nodebelongs to a different document, it will be adopted to the current document. if thenodealready has a parent, it will be orphaned before addition.Will trigger an
EventTypes.APPEND_CHILDevent. Can additionally trigger aEventTypes.REMOVE_CHILDevent on its previous parent, if it has one.- Parameters:
 node- Node- Throws:
 NullPointerException- ifnodeisnull
 - 
prependChild
Adds a child node to start of this element's child nodes.If the specified
nodebelongs to a different document, it will be adopted to the current document. if thenodealready has a parent, it will be orphaned before addition.Will trigger an
EventTypes.APPEND_CHILDevent. Can additionally trigger aEventTypes.REMOVE_CHILDevent on its previous parent, if it has one.- Parameters:
 node- Prepended node- Throws:
 NullPointerException- ifnodeisnull
 - 
insertBefore
Inserts an element before the specified nodeIf the specified
nodebelongs to a different document, it will be adopted to the current document. if thenodealready has a parent, it will be orphaned before addition.If the specified
beforenode does not belong to the children of this element, then nothing happens.Will trigger an
EventTypes.APPEND_CHILDevent. Can additionally trigger aEventTypes.REMOVE_CHILDevent on its previous parent, if it has one.- Parameters:
 node- Node to insertbefore- Node to insert before- Throws:
 NullPointerException- If eithernodeorbeforearenull
 - 
insertAfter
Inserts an element after the specified nodeIf the specified
nodebelongs to a different document, it will be adopted to the current document. if thenodealready has a parent, it will be orphaned before addition.If the specified
afternode does not belong to the children of this element, then nothing happens.Will trigger an
EventTypes.APPEND_CHILDevent. Can additionally trigger aEventTypes.REMOVE_CHILDevent on its previous parent, if it has one.- Parameters:
 node- Node to insertafter- Node to insert after- Throws:
 NullPointerException- If eithernodeorafterarenull
 - 
replaceChild
Replace a child element at the specified index.If the specified node belongs to a different element or document, it will be removed from its previous document and element and adopted to this one.
Will trigger an
EventTypes.REMOVE_CHILDon the child node that's being replaced and then aEventTypes.APPEND_CHILDwhen the node is inserted into the child node list. Can additionally trigger aEventTypes.REMOVE_CHILDevent on the specified node's parent element, if there is one.- Parameters:
 idx- Index of the child to replacenode- Node to replace with- Throws:
 IndexOutOfBoundsException- If the specified index is less than 0 or greater than or equal togetChildCount().NullPointerException- Ifnodeis null.
 - 
replaceChild
Replace a child element at the specified index.If the specified node belongs to a different element or document, it will be removed from its previous document and element and adopted to this one.
If the specified
childis not a child of this element, then nothing happens.Will trigger an
EventTypes.REMOVE_CHILDon the child node that's being replaced and then aEventTypes.APPEND_CHILDwhen the node is inserted into the child node list. Can additionally trigger aEventTypes.REMOVE_CHILDevent on the specified node's parent element, if there is one.- Parameters:
 child- Child to replacenode- Node to replace with- Throws:
 NullPointerException- Ifnodeorchildis null.
 - 
removeChild
Removes a specified child from this element.If the specified
nodeis not a child of this element, thenfalsewill be returned.Will trigger a
EventTypes.REMOVE_CHILDevent. The removed node will be orphaned after removal.- Parameters:
 node- Node to remove- Returns:
 true, if the node was removed,falseif the node was not a child of this element.- Throws:
 NullPointerException- ifnodeisnull- See Also:
 
 - 
removeChild
Removes a child element by its index.Will trigger a
EventTypes.REMOVE_CHILDevent. The removed node will be orphaned after removal.- Parameters:
 childIndex- Index of the child element to remove- Throws:
 IndexOutOfBoundsException- If the specifiedchildIndexis invalid
 - 
removeMatchingChildren
Remove all child nodes that match the specifiedfilterpredicate.Each child that is removed triggers a
EventTypes.REMOVE_CHILDevent. And each removed node will be orphaned after removal.- Parameters:
 filter- Removal filter- Throws:
 NullPointerException- Iffilterisnull
 - 
clearChildren
void clearChildren()Remove all child elements.Children are removed 1 by 1 using the
removeChild(Node)method - 
getChildren
 - 
hasChildren
boolean hasChildren()Tests if this element has children.- Returns:
 true, if the element has children,falseotherwise
 - 
hasChild
Tests if the specifiednodeis a direct child of this element- Parameters:
 node- Node to test- Returns:
 true, ifnodeis a direct child of this element,falseotherwise.
 - 
indexOf
Gets the index of a node that is the direct child of this element.- Parameters:
 node- Direct child node- Returns:
 - The node's index, or 
-1, if the node is not a direct child of this element 
 - 
getChildCount
int getChildCount()Gets the amount of children the element has- Returns:
 - Child count
 
 - 
canHaveChildren
boolean canHaveChildren()Tests if this element is capable of having child nodes.This returns
truein most cases. It returns false if the element's tag is<item>.- Returns:
 true, if this element can support child noes,falseotherwise.
 - 
getChild
Gets the nth child of this element.- Parameters:
 index- Child index from 0 (inclusive) togetChildCount()(exclusive)- Returns:
 - Child node.
 - Throws:
 IndexOutOfBoundsException- Ifindexis less than 0 or greater/equal togetChildCount().
 - 
firstChild
Gets the first child of this element.- Returns:
 - First child, or 
null, if this element has no children 
 - 
lastChild
Gets the last child of this element.- Returns:
 - Last child, or 
null, if this element has no children 
 - 
appendElement
Appends an element and returns it.- Parameters:
 tagName- Element tag name- Returns:
 - Created element
 - Throws:
 NullPointerException- iftagNameisnull- See Also:
 
 - 
appendText
 - 
getTextContent
String getTextContent()Get the element's text content.Returns the joined the text content of all descendants.
- Returns:
 - Text content
 
 - 
setTextContent
Remove all child elements and replace it with the specifiedcontent- Parameters:
 content- New text content
 - 
forEachDescendant
Applies a consumer to all descendant nodes of this element.The specified
consumeris applied to elements in a depth-first traversal.- Parameters:
 consumer- Node consumer- Throws:
 NullPointerException- Ifconsumerisnull
 - 
isDescendant
Test if a specifiednodeis a descendant of the element.- Parameters:
 node- Node to test- Returns:
 true, if thenodeis a descendant of the element,falseotherwise
 - 
matches
Test if the element matches a CSS selector.- Parameters:
 selector- Selector string- Returns:
 true, if the element matches a selector,falseotherwise
 
 -