Interface Element
- All Superinterfaces:
EventTarget
,Node
,SearchContext
- All Known Subinterfaces:
FormControlElement
,FormElement
,FrameElement
,ImageElement
,InputElement
,OptionElement
,SelectElement
,TextAreaElement
All HTML element interfaces derive from this interface.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
Describes how the element will be aligned to the visible area of the scrollable ancestor. -
Method Summary
Modifier and TypeMethodDescriptionReturns an immutable list that contains attribute nodes of the element.Returns an immutable map that contains attributes of the element.attributeValue
(String attrName) Returns a string that represents the value of the attribute with the givenattrName
.void
blur()
Removes keyboard focus from the current element.Returns aRect
object representing the bounds of the element and its position relative to the top-left of the viewport of the current document.void
focus()
Sets focus on this element, if it can be focused.boolean
hasAttribute
(String attrName) Returnstrue
when an attribute with the givenattrName
is specified on this element or has a default value, otherwise returns false.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
Replaces the HTML content of this element with the givenhtml
.Returns a string that represents the text content of the element and its descendants.boolean
Replaces the text content of the element with the giveninnerText
value.Returns a string that represents an HTML serialization of this element and its descendants.boolean
Replaces the element and all of its descendants with a new DOM tree constructed by parsing the givenhtml
.void
putAttribute
(String attrName, String attrValue) Adds a new attribute to the element.void
removeAttribute
(String attrName) Removes an element attribute specified by the givenattrName
.void
scrollIntoView
(Element.AlignTo alignTo) Scrolls the element's parent container such that the element on which this method is called is visible to the user.Methods inherited from interface com.teamdev.jxbrowser.dom.event.EventTarget
addEventListener, dispatch, eventListeners, removeEventListener
Methods inherited from interface com.teamdev.jxbrowser.dom.Node
appendChild, children, click, close, compareDocumentPosition, document, evaluate, evaluate, insertChild, nextSibling, nodeName, nodeValue, nodeValue, parent, previousSibling, removeChild, replaceChild, textContent, textContent, type, xPath
Methods inherited from interface com.teamdev.jxbrowser.dom.SearchContext
findElementByClassName, findElementByCssSelector, findElementById, findElementByName, findElementByTagName, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByName, findElementsByTagName
-
Method Details
-
attributeValue
Returns a string that represents the value of the attribute with the givenattrName
.- Parameters:
attrName
- the attribute name- Returns:
- a string that represents the value of an attribute with the given
attrName
or an empty string if the attribute with the givenattrName
does not exist - Throws:
IllegalArgumentException
- whenattrName
is empty or blankObjectClosedException
- when this instance is closed
-
putAttribute
Adds a new attribute to the element. If an attribute with the givenattrName
is already defined in the element, its value will be replaced with the new one.- Parameters:
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 value- Throws:
IllegalArgumentException
- whenattrName
is empty or blankObjectClosedException
- when this instance is closed
-
removeAttribute
Removes an element attribute specified by the givenattrName
. This method does nothing if the element does not have theattrName
attribute.- Parameters:
attrName
- the name of the attribute to remove- Throws:
IllegalArgumentException
- whenattrName
is empty or blankObjectClosedException
- when this instance is closed
-
hasAttribute
Returnstrue
when an attribute with the givenattrName
is specified on this element or has a default value, otherwise returns false.- Parameters:
attrName
- the name of the attribute- Throws:
IllegalArgumentException
- whenattrName
is empty or blankObjectClosedException
- when this instance is closed
-
attributes
Returns an immutable map that contains attributes of the element. Each map entry represents a pair of strings wherekey
stands for the attribute name andvalue
stands for the attribute value. Returns an empty map if the element does not have attributes.- Throws:
ObjectClosedException
- when this instance is closed
-
attributeNodes
Returns an immutable list that contains attribute nodes of the element. Each list entry represents an attribute node. Returns an empty list if the element does not have attributes.- Throws:
ObjectClosedException
- when this instance is closed
-
innerHtml
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.- Throws:
ObjectClosedException
- when this instance is closed
-
innerHtml
Replaces the HTML content of this element with the givenhtml
.- Parameters:
html
- a new HTML content of this element- Returns:
true
when the HTML content of the element was successfully replaced- Throws:
ObjectClosedException
- when this instance is closed
-
outerHtml
String outerHtml()Returns a string that represents an HTML serialization of this element and its descendants.- Throws:
ObjectClosedException
- when this instance is closed- Since:
- 7.1
-
outerHtml
Replaces the element and all of its descendants with a new DOM tree constructed by parsing the givenhtml
.- Parameters:
html
- a new HTML of this element- Returns:
true
when the HTML of the element was successfully replaced- Throws:
ObjectClosedException
- when this instance is closed- Since:
- 7.1
-
innerText
String innerText()Returns a string that represents the text content of the element and its descendants. This method can return an empty string if the element does not have a content.- Throws:
ObjectClosedException
- when this instance is closed
-
innerText
Replaces the text content of the element with the giveninnerText
value. Assigning a new value to the inner text will destroy any descendants of the element.- Parameters:
innerText
- a new text content of the element- Returns:
true
when the text content of the element was successfully replaced- Throws:
ObjectClosedException
- when this instance is closed
-
boundingClientRect
Rect boundingClientRect()Returns aRect
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 thehidden
attribute or the CSS style of the element containsdisplay: 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
andwindow.scrollY
) to get a bounding rectangle which is independent from the current scrolling position.- Throws:
ObjectClosedException
- when this instance is closed
-
focus
void focus()Sets focus on this element, if it can be focused. The focused element is the element which will receive keyboard and similar events by default.This method does nothing if the browser instance where the web page with this element is loaded is not focused. To programmatically focus the browser instance use the
Browser.focus()
method.- Throws:
ObjectClosedException
- when this instance is closed- Since:
- 7.1
-
blur
void blur()Removes keyboard focus from the current element.This method does nothing if the browser instance where the web page with this element is loaded is not focused. To programmatically focus the browser instance use the
Browser.focus()
method.- Throws:
ObjectClosedException
- when this instance is closed- Since:
- 7.1
-
scrollIntoView
Scrolls the element's parent container such that the element on which this method is called is visible to the user.Note: that the element may not be scrolled completely to the top or bottom depending on the layout of other elements.
- Parameters:
alignTo
- describes how the element will be aligned to the visible area of the scrollable ancestor- Throws:
ObjectClosedException
- when the document of this element is closed- Since:
- 7.5
-