GWT 2.7.0

com.google.gwt.dom.client
Class Element

java.lang.Object
  extended by com.google.gwt.core.client.JavaScriptObject
      extended by com.google.gwt.dom.client.Node
          extended by com.google.gwt.dom.client.Element
Direct Known Subclasses:
AbstractImagePrototype.ImagePrototypeElement, AnchorElement, AreaElement, BaseElement, BodyElement, BRElement, ButtonElement, CanvasElement, DivElement, DListElement, Element, FieldSetElement, FormElement, FrameElement, FrameSetElement, HeadElement, HeadingElement, HRElement, IFrameElement, ImageElement, InputElement, LabelElement, LegendElement, LIElement, LinkElement, MapElement, MediaElement, MetaElement, ModElement, ObjectElement, OListElement, OptGroupElement, OptionElement, ParagraphElement, ParamElement, PotentialElement, PreElement, QuoteElement, ScriptElement, SelectElement, SourceElement, SpanElement, StyleElement, TableCaptionElement, TableCellElement, TableColElement, TableElement, TableRowElement, TableSectionElement, TextAreaElement, TitleElement, UListElement

public class Element
extends Node

All HTML element interfaces derive from this class.


Field Summary
static java.lang.String DRAGGABLE_AUTO
          Constant returned from getDraggable().
static java.lang.String DRAGGABLE_FALSE
          Constant returned from getDraggable().
static java.lang.String DRAGGABLE_TRUE
          Constant returned from getDraggable().
 
Fields inherited from class com.google.gwt.dom.client.Node
DOCUMENT_NODE, ELEMENT_NODE, TEXT_NODE
 
Constructor Summary
protected Element()
           
 
Method Summary
 boolean addClassName(java.lang.String className)
          Adds a name to this element's class property.
static Element as(JavaScriptObject o)
          Assert that the given Node is an Element and automatically typecast it.
static Element as(Node node)
          Assert that the given Node is an Element and automatically typecast it.
 void blur()
          Removes keyboard focus from this element.
 void dispatchEvent(NativeEvent evt)
          Dispatched the given event with this element as its target.
 void focus()
          Gives keyboard focus to this element.
 int getAbsoluteBottom()
          Gets an element's absolute bottom coordinate in the document's coordinate system.
 int getAbsoluteLeft()
          Gets an element's absolute left coordinate in the document's coordinate system.
 int getAbsoluteRight()
          Gets an element's absolute right coordinate in the document's coordinate system.
 int getAbsoluteTop()
          Gets an element's absolute top coordinate in the document's coordinate system.
 java.lang.String getAttribute(java.lang.String name)
          Retrieves an attribute value by name.
 java.lang.String getClassName()
          The class attribute of the element.
 int getClientHeight()
          Returns the inner height of an element in pixels, including padding but not the horizontal scrollbar height, border, or margin.
 int getClientWidth()
          Returns the inner width of an element in pixels, including padding but not the vertical scrollbar width, border, or margin.
 java.lang.String getDir()
          Specifies the base direction of directionally neutral text and the directionality of tables.
 java.lang.String getDraggable()
          Returns the draggable attribute of this element.
 NodeList<Element> getElementsByTagName(java.lang.String name)
          Returns a NodeList of all descendant Elements with a given tag name, in the order in which they are encountered in a preorder traversal of this Element tree.
 Element getFirstChildElement()
          The first child of element this element.
 java.lang.String getId()
          The element's identifier.
 java.lang.String getInnerHTML()
          All of the markup and content within a given element.
 java.lang.String getInnerText()
          The text between the start and end tags of the object.
 java.lang.String getLang()
          Language code defined in RFC 1766.
 Element getNextSiblingElement()
          The element immediately following this element.
 int getOffsetHeight()
          The height of an element relative to the layout.
 int getOffsetLeft()
          The number of pixels that the upper left corner of the current element is offset to the left within the offsetParent node.
 Element getOffsetParent()
          Returns a reference to the object which is the closest (nearest in the containment hierarchy) positioned containing element.
 int getOffsetTop()
          The number of pixels that the upper top corner of the current element is offset to the top within the offsetParent node.
 int getOffsetWidth()
          The width of an element relative to the layout.
 Element getPreviousSiblingElement()
          The element immediately preceeding this element.
 boolean getPropertyBoolean(java.lang.String name)
          Gets a boolean property from this element.
 double getPropertyDouble(java.lang.String name)
          Gets a double property from this element.
 int getPropertyInt(java.lang.String name)
          Gets an integer property from this element.
 JavaScriptObject getPropertyJSO(java.lang.String name)
          Gets a JSO property from this element.
 java.lang.Object getPropertyObject(java.lang.String name)
          Gets an object property from this element.
 java.lang.String getPropertyString(java.lang.String name)
          Gets a property from this element.
 int getScrollHeight()
          The height of the scroll view of an element.
 int getScrollLeft()
          The number of pixels that an element's content is scrolled from the left.
 int getScrollTop()
          The number of pixels that an element's content is scrolled from the top.
 int getScrollWidth()
          The width of the scroll view of an element.
 java.lang.String getString()
          Gets a string representation of this element (as outer HTML).
 Style getStyle()
          Gets this element's Style object.
 int getTabIndex()
          The index that represents the element's position in the tabbing order.
 java.lang.String getTagName()
          Gets the element's full tag name, including the namespace-prefix if present.
 java.lang.String getTitle()
          The element's advisory title.
 boolean hasAttribute(java.lang.String name)
          Determines whether an element has an attribute with a given name.
 boolean hasClassName(java.lang.String className)
          Checks if this element's class property contains specified class name.
 boolean hasTagName(java.lang.String tagName)
          Determines whether this element has the given tag name.
(package private) static int indexOfName(java.lang.String nameList, java.lang.String name)
          Returns the index of the first occurrence of name in a space-separated list of names, or -1 if not found.
static boolean is(JavaScriptObject o)
          Determines whether the given JavaScriptObject can be cast to an Element.
static boolean is(Node node)
          Determine whether the given Node can be cast to an Element.
 void removeAttribute(java.lang.String name)
          Removes an attribute by name.
 boolean removeClassName(java.lang.String className)
          Removes a name from this element's class property.
 void replaceClassName(java.lang.String oldClassName, java.lang.String newClassName)
          Replace one class name with another.
 void scrollIntoView()
          Scrolls this element into view.
 void setAttribute(java.lang.String name, java.lang.String value)
          Adds a new attribute.
 void setClassName(java.lang.String className)
          The class attribute of the element.
 void setDir(java.lang.String dir)
          Specifies the base direction of directionally neutral text and the directionality of tables.
 void setDraggable(java.lang.String draggable)
          Changes the draggable attribute to one of DRAGGABLE_AUTO, DRAGGABLE_FALSE, or DRAGGABLE_TRUE.
 void setId(java.lang.String id)
          The element's identifier.
 void setInnerHTML(java.lang.String html)
          All of the markup and content within a given element.
 void setInnerSafeHtml(SafeHtml html)
          All of the markup and content within a given element.
 void setInnerText(java.lang.String text)
          The text between the start and end tags of the object.
 void setLang(java.lang.String lang)
          Language code defined in RFC 1766.
 void setPropertyBoolean(java.lang.String name, boolean value)
          Sets a boolean property on this element.
 void setPropertyDouble(java.lang.String name, double value)
          Sets a double property on this element.
 void setPropertyInt(java.lang.String name, int value)
          Sets an integer property on this element.
 void setPropertyJSO(java.lang.String name, JavaScriptObject value)
          Sets a JSO property on this element.
 void setPropertyObject(java.lang.String name, java.lang.Object value)
          Sets an object property on this element.
 void setPropertyString(java.lang.String name, java.lang.String value)
          Sets a property on this element.
 void setScrollLeft(int scrollLeft)
          The number of pixels that an element's content is scrolled to the left.
 void setScrollTop(int scrollTop)
          The number of pixels that an element's content is scrolled to the top.
 void setTabIndex(int tabIndex)
          The index that represents the element's position in the tabbing order.
 void setTitle(java.lang.String title)
          The element's advisory title.
 void toggleClassName(java.lang.String className)
          Add the class name if it doesn't exist or removes it if does.
 
Methods inherited from class com.google.gwt.dom.client.Node
appendChild, cloneNode, getChild, getChildCount, getChildNodes, getFirstChild, getLastChild, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentElement, getParentNode, getPreviousSibling, hasChildNodes, hasParentElement, insertAfter, insertBefore, insertFirst, isOrHasChild, removeAllChildren, removeChild, removeFromParent, replaceChild, setNodeValue
 
Methods inherited from class com.google.gwt.core.client.JavaScriptObject
cast, createArray, createArray, createFunction, createObject, equals, hashCode, toSource, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DRAGGABLE_AUTO

public static final java.lang.String DRAGGABLE_AUTO
Constant returned from getDraggable().

See Also:
Constant Field Values

DRAGGABLE_FALSE

public static final java.lang.String DRAGGABLE_FALSE
Constant returned from getDraggable().

See Also:
Constant Field Values

DRAGGABLE_TRUE

public static final java.lang.String DRAGGABLE_TRUE
Constant returned from getDraggable().

See Also:
Constant Field Values
Constructor Detail

Element

protected Element()
Method Detail

as

public static Element as(JavaScriptObject o)
Assert that the given Node is an Element and automatically typecast it.


as

public static Element as(Node node)
Assert that the given Node is an Element and automatically typecast it.


is

public static boolean is(JavaScriptObject o)
Determines whether the given JavaScriptObject can be cast to an Element. A null object will cause this method to return false.


is

public static boolean is(Node node)
Determine whether the given Node can be cast to an Element. A null node will cause this method to return false.


addClassName

public final boolean addClassName(java.lang.String className)
Adds a name to this element's class property. If the name is already present, this method has no effect.

Parameters:
className - the class name to be added
Returns:
true if this element did not already have the specified class name
See Also:
setClassName(String)

blur

public final void blur()
Removes keyboard focus from this element.


dispatchEvent

public final void dispatchEvent(NativeEvent evt)
Dispatched the given event with this element as its target. The event will go through all phases of the browser's normal event dispatch mechanism. Note: Because the browser's normal dispatch mechanism is used, exceptions thrown from within handlers triggered by this method cannot be caught by wrapping this method in a try/catch block. Such exceptions will be caught by the uncaught exception handler as usual.

Parameters:
evt - the event to be dispatched

focus

public final void focus()
Gives keyboard focus to this element.


getAbsoluteBottom

public final int getAbsoluteBottom()
Gets an element's absolute bottom coordinate in the document's coordinate system.


getAbsoluteLeft

public final int getAbsoluteLeft()
Gets an element's absolute left coordinate in the document's coordinate system.


getAbsoluteRight

public final int getAbsoluteRight()
Gets an element's absolute right coordinate in the document's coordinate system.


getAbsoluteTop

public final int getAbsoluteTop()
Gets an element's absolute top coordinate in the document's coordinate system.


getAttribute

public final java.lang.String getAttribute(java.lang.String name)
Retrieves an attribute value by name. Attribute support can be inconsistent across various browsers. Consider using the accessors in Element and its specific subclasses to retrieve attributes and properties.

Parameters:
name - The name of the attribute to retrieve
Returns:
The Attr value as a string, or the empty string if that attribute does not have a specified or default value

getClassName

public final java.lang.String getClassName()
The class attribute of the element. This attribute has been renamed due to conflicts with the "class" keyword exposed by many languages.

See Also:
W3C HTML Specification

getClientHeight

public final int getClientHeight()
Returns the inner height of an element in pixels, including padding but not the horizontal scrollbar height, border, or margin.

Returns:
the element's client height

getClientWidth

public final int getClientWidth()
Returns the inner width of an element in pixels, including padding but not the vertical scrollbar width, border, or margin.

Returns:
the element's client width

getDir

public final java.lang.String getDir()
Specifies the base direction of directionally neutral text and the directionality of tables.


getDraggable

public final java.lang.String getDraggable()
Returns the draggable attribute of this element.

Returns:
one of DRAGGABLE_AUTO, DRAGGABLE_FALSE, or DRAGGABLE_TRUE

getElementsByTagName

public final NodeList<Element> getElementsByTagName(java.lang.String name)
Returns a NodeList of all descendant Elements with a given tag name, in the order in which they are encountered in a preorder traversal of this Element tree.

Parameters:
name - The name of the tag to match on. The special value "*" matches all tags
Returns:
A list of matching Element nodes

getFirstChildElement

public final Element getFirstChildElement()
The first child of element this element. If there is no such element, this returns null.


getId

public final java.lang.String getId()
The element's identifier.

See Also:
W3C HTML Specification

getInnerHTML

public final java.lang.String getInnerHTML()
All of the markup and content within a given element.


getInnerText

public final java.lang.String getInnerText()
The text between the start and end tags of the object.


getLang

public final java.lang.String getLang()
Language code defined in RFC 1766.


getNextSiblingElement

public final Element getNextSiblingElement()
The element immediately following this element. If there is no such element, this returns null.


getOffsetHeight

public final int getOffsetHeight()
The height of an element relative to the layout.


getOffsetLeft

public final int getOffsetLeft()
The number of pixels that the upper left corner of the current element is offset to the left within the offsetParent node.


getOffsetParent

public final Element getOffsetParent()
Returns a reference to the object which is the closest (nearest in the containment hierarchy) positioned containing element.


getOffsetTop

public final int getOffsetTop()
The number of pixels that the upper top corner of the current element is offset to the top within the offsetParent node.


getOffsetWidth

public final int getOffsetWidth()
The width of an element relative to the layout.


getPreviousSiblingElement

public final Element getPreviousSiblingElement()
The element immediately preceeding this element. If there is no such element, this returns null.


getPropertyBoolean

public final boolean getPropertyBoolean(java.lang.String name)
Gets a boolean property from this element.

Parameters:
name - the name of the property to be retrieved
Returns:
the property value

getPropertyDouble

public final double getPropertyDouble(java.lang.String name)
Gets a double property from this element.

Parameters:
name - the name of the property to be retrieved
Returns:
the property value

getPropertyInt

public final int getPropertyInt(java.lang.String name)
Gets an integer property from this element.

Parameters:
name - the name of the property to be retrieved
Returns:
the property value

getPropertyJSO

public final JavaScriptObject getPropertyJSO(java.lang.String name)
Gets a JSO property from this element.

Parameters:
name - the name of the property to be retrieved
Returns:
the property value

getPropertyObject

public final java.lang.Object getPropertyObject(java.lang.String name)
Gets an object property from this element.

Parameters:
name - the name of the property to be retrieved
Returns:
the property value

getPropertyString

public final java.lang.String getPropertyString(java.lang.String name)
Gets a property from this element.

Parameters:
name - the name of the property to be retrieved
Returns:
the property value

getScrollHeight

public final int getScrollHeight()
The height of the scroll view of an element.


getScrollLeft

public final int getScrollLeft()
The number of pixels that an element's content is scrolled from the left.

If the element is in RTL mode, this method will return a negative value of the number of pixels scrolled from the right.


getScrollTop

public final int getScrollTop()
The number of pixels that an element's content is scrolled from the top.


getScrollWidth

public final int getScrollWidth()
The width of the scroll view of an element.


getString

public final java.lang.String getString()
Gets a string representation of this element (as outer HTML). We do not override JavaScriptObject.toString() because it is final in JavaScriptObject.

Returns:
the string representation of this element

getStyle

public final Style getStyle()
Gets this element's Style object.


getTabIndex

public final int getTabIndex()
The index that represents the element's position in the tabbing order.

See Also:
W3C HTML Specification

getTagName

public final java.lang.String getTagName()
Gets the element's full tag name, including the namespace-prefix if present.

Returns:
the element's tag name

getTitle

public final java.lang.String getTitle()
The element's advisory title.


hasAttribute

public final boolean hasAttribute(java.lang.String name)
Determines whether an element has an attribute with a given name.

Note that IE, prior to version 8, will return false-positives for names that collide with element properties (e.g., style, width, and so forth).

Parameters:
name - the name of the attribute
Returns:
true if this element has the specified attribute

hasClassName

public final boolean hasClassName(java.lang.String className)
Checks if this element's class property contains specified class name.

Parameters:
className - the class name to be added
Returns:
true if this element has the specified class name

hasTagName

public final boolean hasTagName(java.lang.String tagName)
Determines whether this element has the given tag name.

Parameters:
tagName - the tag name, including namespace-prefix (if present)
Returns:
true if the element has the given tag name

removeAttribute

public final void removeAttribute(java.lang.String name)
Removes an attribute by name.


removeClassName

public final boolean removeClassName(java.lang.String className)
Removes a name from this element's class property. If the name is not present, this method has no effect.

Parameters:
className - the class name to be removed
Returns:
true if this element had the specified class name
See Also:
setClassName(String)

indexOfName

static int indexOfName(java.lang.String nameList,
                       java.lang.String name)
Returns the index of the first occurrence of name in a space-separated list of names, or -1 if not found.

Parameters:
nameList - list of space delimited names
name - a non-empty string. Should be already trimmed.

toggleClassName

public final void toggleClassName(java.lang.String className)
Add the class name if it doesn't exist or removes it if does.

Parameters:
className - the class name to be toggled

replaceClassName

public final void replaceClassName(java.lang.String oldClassName,
                                   java.lang.String newClassName)
Replace one class name with another.

Parameters:
oldClassName - the class name to be replaced
newClassName - the class name to replace it

scrollIntoView

public final void scrollIntoView()
Scrolls this element into view.

This method crawls up the DOM hierarchy, adjusting the scrollLeft and scrollTop properties of each scrollable element to ensure that the specified element is completely in view. It adjusts each scroll position by the minimum amount necessary.


setAttribute

public final void setAttribute(java.lang.String name,
                               java.lang.String value)
Adds a new attribute. If an attribute with that name is already present in the element, its value is changed to be that of the value parameter.

Parameters:
name - The name of the attribute to create or alter
value - Value to set in string form

setClassName

public final void setClassName(java.lang.String className)
The class attribute of the element. This attribute has been renamed due to conflicts with the "class" keyword exposed by many languages.

See Also:
W3C HTML Specification

setDir

public final void setDir(java.lang.String dir)
Specifies the base direction of directionally neutral text and the directionality of tables.


setDraggable

public final void setDraggable(java.lang.String draggable)
Changes the draggable attribute to one of DRAGGABLE_AUTO, DRAGGABLE_FALSE, or DRAGGABLE_TRUE.

Parameters:
draggable - a String constants

setId

public final void setId(java.lang.String id)
The element's identifier.

See Also:
W3C HTML Specification

setInnerHTML

public final void setInnerHTML(java.lang.String html)
All of the markup and content within a given element.


setInnerSafeHtml

public final void setInnerSafeHtml(SafeHtml html)
All of the markup and content within a given element.


setInnerText

public final void setInnerText(java.lang.String text)
The text between the start and end tags of the object.


setLang

public final void setLang(java.lang.String lang)
Language code defined in RFC 1766.


setPropertyBoolean

public final void setPropertyBoolean(java.lang.String name,
                                     boolean value)
Sets a boolean property on this element.

Parameters:
name - the name of the property to be set
value - the new property value

setPropertyDouble

public final void setPropertyDouble(java.lang.String name,
                                    double value)
Sets a double property on this element.

Parameters:
name - the name of the property to be set
value - the new property value

setPropertyInt

public final void setPropertyInt(java.lang.String name,
                                 int value)
Sets an integer property on this element.

Parameters:
name - the name of the property to be set
value - the new property value

setPropertyJSO

public final void setPropertyJSO(java.lang.String name,
                                 JavaScriptObject value)
Sets a JSO property on this element.

Parameters:
name - the name of the property to be set
value - the new property value

setPropertyObject

public final void setPropertyObject(java.lang.String name,
                                    java.lang.Object value)
Sets an object property on this element.

Parameters:
name - the name of the property to be set
value - the new property value

setPropertyString

public final void setPropertyString(java.lang.String name,
                                    java.lang.String value)
Sets a property on this element.

Parameters:
name - the name of the property to be set
value - the new property value

setScrollLeft

public final void setScrollLeft(int scrollLeft)
The number of pixels that an element's content is scrolled to the left.


setScrollTop

public final void setScrollTop(int scrollTop)
The number of pixels that an element's content is scrolled to the top.


setTabIndex

public final void setTabIndex(int tabIndex)
The index that represents the element's position in the tabbing order.

See Also:
W3C HTML Specification

setTitle

public final void setTitle(java.lang.String title)
The element's advisory title.


GWT 2.7.0