Interface Element
- All Superinterfaces:
DomQueryable,EventTarget,Node
- All Known Subinterfaces:
ButtonElement,ItemElement
Elements are not guaranteed to have children. An element can only support children if
canHaveChildren() returns true.
-
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.@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 valueGet the modifiable inline style properties.Gets the element's tag name.Get the element's text content.@Nullable NodeGets the element's title node.@Nullable NodeGets the element's tooltip.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 node@Nullable NodeGets the last child of this element.voidprependChild(@NotNull Node node) Adds a child node to start of this element's child nodes.voidremoveChild(int childIndex) Removes a child element by its index.booleanremoveChild(@NotNull Node node) Removes a specified child from this element.voidsetAttribute(@NotNull String key, @Nullable String value) Sets an attribute's value.default voidsetClassList(@Nullable Collection<String> classList) Sets the element's class list.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 Node title) Sets the element's title node.Methods inherited from interface net.arcadiusmc.dom.DomQueryable
getElementsByClassName, getElementsByTagName, querySelector, querySelectorAllMethods inherited from interface net.arcadiusmc.dom.event.EventTarget
addEventListener, dispatchEvent, removeEventListenerMethods inherited from interface net.arcadiusmc.dom.Node
enterVisitor, exitVisitor, getDepth, getOwningDocument, getParent, getSiblingIndex, hasFlag, nextSibling, previousSibling
-
Method Details
-
getInlineStyle
StyleProperties getInlineStyle()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
Gets the value of an attribute.- Parameters:
key- Attribute key- Returns:
- Attribute value, or
null, if not set, or ifkeyisnull.
-
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
-
getAttributeNames
Get a set of attribute keys that exist on this element.- Returns:
- Unmodifiable key set
-
getAttributeEntries
Gets a set of attribute entries that exist on this element.- Returns:
- Unmodifiable entry set
-
getId
Shorthand for getting the id attribute's value- Returns:
- Element ID
- See Also:
-
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.- Returns:
- An array list containing all the classes of this element.
-
setClassList
Sets the element's class list.- Parameters:
classList- Class list, ornull, to remove classes.
-
getTagName
String getTagName()Gets the element's tag name.- Returns:
- Tag name
-
getTooltip
Gets the element's tooltip.- Returns:
- Tooltip node
- See Also:
-
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
-
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
-
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
-
getChildren
Gets an immutable list of child nodes- Returns:
- Child node list
-
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
Creates a text node and appends it to this element- Parameters:
text- Text content- Returns:
- Created node
- See Also:
-
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
-