public interface Element extends Node
All HTML element interfaces derive from this interface.
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.String> |
attributes()
Returns an immutable map that contains attributes of the element.
|
java.lang.String |
attributeValue(java.lang.String attrName)
Returns a string that represents the value of the attribute with the given
attrName . |
Rect |
boundingClientRect()
Returns a
Rect object representing the bounds of the element and its position
relative to the top-left of the viewport of the current document. |
boolean |
hasAttribute(java.lang.String attrName)
Returns
true when an attribute with the given attrName is specified on this
element or has a default value, otherwise returns false. |
java.lang.String |
innerHtml()
Returns a string that represents the HTML content of this element or an empty string if the
element does not have the inner HTML.
|
boolean |
innerHtml(java.lang.String html)
Replaces the HTML content of this element with the given
html . |
java.lang.String |
innerText()
Returns a string that represents the text content of the element and its descendants.
|
boolean |
innerText(java.lang.String innerText)
Replaces the text content of the element with the given
innerText value. |
void |
putAttribute(java.lang.String attrName,
java.lang.String attrValue)
Adds a new attribute to the element.
|
void |
removeAttribute(java.lang.String attrName)
Removes an element attribute specified by the given
attrName . |
appendChild, children, click, evaluate, evaluate, insertChild, nextSibling, nodeName, nodeValue, nodeValue, parent, previousSibling, removeChild, replaceChild, textContent, textContent, type
addEventListener, dispatch, eventListeners, removeEventListener
findElementByClassName, findElementByCssSelector, findElementById, findElementByName, findElementByTagName, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByName, findElementsByTagName
java.lang.String attributeValue(java.lang.String attrName)
attrName
.attrName
- the attribute nameattrName
or
an empty string if the attribute with the given attrName
does not existjava.lang.IllegalArgumentException
- when attrName
is empty or blankjava.lang.IllegalStateException
- when the document this instance belongs to is closedvoid putAttribute(java.lang.String attrName, java.lang.String attrValue)
attrName
is
already defined in the element, its value will be replaced with the new one.attrName
- the name of the attribute to create or alterattrValue
- value to set in string form. Can be empty for boolean attribute names which
are always true despite the attribute valuejava.lang.IllegalArgumentException
- when attrName
is empty or blankjava.lang.IllegalStateException
- when the document this instance belongs to is closedvoid removeAttribute(java.lang.String attrName)
attrName
. This method does
nothing if the element does not have the attrName
attribute.attrName
- the name of the attribute to removejava.lang.IllegalArgumentException
- when attrName
is empty or blankjava.lang.IllegalStateException
- when the document this instance belongs to is closedboolean hasAttribute(java.lang.String attrName)
true
when an attribute with the given attrName
is specified on this
element or has a default value, otherwise returns false.attrName
- the name of the attributejava.lang.IllegalArgumentException
- when attrName
is empty or blankjava.lang.IllegalStateException
- when the document this instance belongs to is closedjava.util.Map<java.lang.String,java.lang.String> attributes()
key
stands for the attribute name and value
stands for
the attribute value. Returns an empty map if the element does not have attributes.java.lang.IllegalStateException
- when the document this instance belongs to is closedjava.lang.String innerHtml()
java.lang.IllegalStateException
- when the document this instance belongs to is closedboolean innerHtml(java.lang.String html)
html
.html
- a new HTML content of this elementtrue
when the HTML content of the element was successfully replacedjava.lang.IllegalStateException
- when the document this instance belongs to is closedjava.lang.String innerText()
java.lang.IllegalStateException
- when the document this instance belongs to is closedboolean innerText(java.lang.String innerText)
innerText
value. Assigning a
new value to the inner text will destroy any descendants of the element.innerText
- a new text content of the elementtrue
when the text content of the element was successfully replacedjava.lang.IllegalStateException
- when the document this instance belongs to is closedRect boundingClientRect()
Rect
object representing the bounds of the element and its position
relative to the top-left of the viewport of the current document.
This method can return a Rect
with zero width, height, x, and y if the element
has the hidden
attribute or the CSS style of the element contains display:
none;
statement.
The amount of scrolling that has been done of the viewport area (or any other scrollable
element) is taken into account when computing the bounding rectangle. This means that the
rectangle's boundary edges (top, left, bottom, and right) change their values every time the
scrolling position changes (because their values are relative to the viewport and not
absolute). If you need the bounding rectangle relative to the top-left corner of the
document, just add the current scrolling position to the top and left properties (these can
be obtained using window.scrollX
and window.scrollY
) to get a bounding
rectangle which is independent from the current scrolling position.
java.lang.IllegalStateException
- when the document this instance belongs to is closed