public interface ElementTraversal
The ElementTraversal interface is a set of properties on the
Element
object, which allow an author to easily navigate
between elements.
Note: This interface has not yet been accepted for inclusion in the W3C DOM 3 specification. It may be removed from the JSR 280 specification or added to a different namespace in a subsequent version of the specification.
Four of the properties,firstElementChild
,
lastElementChild
, previousElementSibling
, and
nextElementSibling
, each provide a live reference to another
element with the defined relationship to the current element, if the related
element exists. The fifth property, childElementCount
, exposes
the number of child elements of an element, for preprocessing before
navigation. A conforming implementation must implement all five methods. An
implementation may implement similar interfaces in other specifications, but
such implementation is not required for conformance to this specification,
if the implementation is designed for a minimal code footprint.
This interface must be implemented on all elements, regardless of their
namespace. For the purpose of ElementTraversal, an entity reference node
which represents an element must be treated as an element node. Navigation
must be irrespective of namespace, e.g. if an element in the HTML namespace
is followed by element in the SVG namespace, nextElementSibling
will allow you to navigate from the HTML element to the SVG element.
Modifier and Type | Method and Description |
---|---|
int |
getChildElementCount()
Retrieves the number of child elements.
|
Element |
getFirstElementChild()
Retrieves the first child element.
|
Element |
getLastElementChild()
Retrieves the last child element.
|
Element |
getNextElementSibling()
Retrieves the next sibling element.
|
Element |
getPreviousElementSibling()
Retrieves the previous sibling element.
|
int getChildElementCount()
0
if this element has no child elements.Element getFirstElementChild()
null
if this element has no child elements.Element getLastElementChild()
null
if this element has no child elements.Element getNextElementSibling()
null
if this element has no element sibling nodes
that come after this one in the document tree.Element getPreviousElementSibling()
null
if this element has no element sibling nodes
that come before this one in the document tree.