Class HtmlElement

java.lang.Object
org.apache.juneau.bean.html5.HtmlElement
Direct Known Subclasses:
HtmlElementContainer, HtmlElementMixed, HtmlElementRawText, HtmlElementText, HtmlElementVoid

@Html(format=XML) public abstract class HtmlElement extends Object
Superclass for all HTML elements.

These are beans that when serialized using HtmlSerializer generate valid HTML5 elements.

See Also:
  • Constructor Details

  • Method Details

    • getAttrs

      The attributes of this element.
      Returns:
      The attributes of this element.
    • setAttrs

      @Beanp("a") public HtmlElement setAttrs(Map<String,Object> attrs)
      Sets the attributes for this element.
      Parameters:
      attrs - The new attributes for this element.
      Returns:
      This object.
    • attr

      public HtmlElement attr(String key, Object val)
      Adds an arbitrary attribute to this element.
      Parameters:
      key - The attribute name.
      val - The attribute value.
      Returns:
      This object.
    • attrUri

      public HtmlElement attrUri(String key, Object val)
      Adds an arbitrary URI attribute to this element.

      Same as attr(String, Object), except if the value is a string that appears to be a URI (e.g. "servlet:/xxx").

      The value can be of any of the following types: URI, URL, String. Strings must be valid URIs.

      URIs defined by UriResolver can be used for values.

      Parameters:
      key - The attribute name.
      val - The attribute value.
      Returns:
      This object.
    • getAttr

      public String getAttr(String key)
      Returns the attribute with the specified name.
      Parameters:
      key - The attribute name.
      Returns:
      The attribute value, or null if the named attribute does not exist.
    • getAttr

      public <T> T getAttr(Class<T> type, String key)
      Returns the attribute with the specified name converted to the specified class type.
      Type Parameters:
      T - The class type to convert this class to.
      Parameters:
      type - The class type to convert this class to. See ConverterUtils for a list of supported conversion types.
      key - The attribute name.
      Returns:
      The attribute value, or null if the named attribute does not exist.
    • accesskey

      public HtmlElement accesskey(String value)
      accesskey attribute.

      Defines a keyboard shortcut to activate or focus an element. The value should be a single character that, when pressed with a modifier key (usually Alt), activates the element.

      Parameters:
      accesskey - The keyboard shortcut character (e.g., "a", "1").
      Returns:
      This object.
    • _class

      public HtmlElement _class(String value)
      class attribute.

      Specifies one or more CSS class names for the element, separated by spaces. These classes can be used for styling and JavaScript selection.

      Parameters:
      _class - Space-separated CSS class names (e.g., "btn btn-primary").
      Returns:
      This object.
    • contenteditable

      contenteditable attribute.

      Indicates whether the element's content is editable by the user.

      Possible values:

      • "true" or empty string - Element content is editable
      • "false" - Element content is not editable
      • "plaintext-only" - Element content is editable, but rich text formatting is disabled
      Parameters:
      contenteditable - The editability state of the element.
      Returns:
      This object.
    • dir

      public HtmlElement dir(String value)
      dir attribute.

      Specifies the text direction of the element's content.

      Possible values:

      • "ltr" - Left-to-right text direction
      • "rtl" - Right-to-left text direction
      • "auto" - Browser determines direction based on content
      Parameters:
      dir - The text direction for the element.
      Returns:
      This object.
    • hidden

      public HtmlElement hidden(Object value)
      hidden attribute.

      This attribute uses deminimized values:

      • false - Attribute is not added
      • true - Attribute is added as "hidden"
      • Other values - Passed through as-is
      Parameters:
      hidden - The new value for this attribute. Typically a Boolean or String.
      Returns:
      This object.
    • id

      public HtmlElement id(String value)
      id attribute.

      Specifies a unique identifier for the element. The ID must be unique within the document and can be used for CSS styling, JavaScript selection, and anchor links.

      Parameters:
      id - A unique identifier for the element (e.g., "header", "main-content").
      Returns:
      This object.
    • lang

      public HtmlElement lang(String value)
      lang attribute.

      Specifies the primary language of the element's content using a language tag. This helps with accessibility, search engines, and browser features like spell checking.

      Parameters:
      lang - A language tag (e.g., "en", "en-US", "es", "fr-CA").
      Returns:
      This object.
    • onabort

      public HtmlElement onabort(String value)
      onabort attribute.

      Event handler for when an operation is aborted (e.g., image loading is cancelled).

      Parameters:
      onabort - JavaScript code to execute when the abort event occurs.
      Returns:
      This object.
    • onblur

      public HtmlElement onblur(String value)
      onblur attribute.

      Event handler for when the element loses focus.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onblur("validate(\"email\")")
      • If using double quotes for attributes: onblur("validate('email')")
      Parameters:
      onblur - JavaScript code to execute when the element loses focus.
      Returns:
      This object.
    • oncancel

      public HtmlElement oncancel(String value)
      oncancel attribute.

      Event handler for when a dialog is cancelled.

      Parameters:
      oncancel - JavaScript code to execute when the cancel event occurs.
      Returns:
      This object.
    • oncanplay

      public HtmlElement oncanplay(String value)
      oncanplay attribute.

      Event handler for when the media can start playing (enough data has been buffered).

      Parameters:
      oncanplay - JavaScript code to execute when the canplay event occurs.
      Returns:
      This object.
    • oncanplaythrough

      oncanplaythrough attribute.

      Event handler for when the media can play through to the end without buffering.

      Parameters:
      oncanplaythrough - JavaScript code to execute when the canplaythrough event occurs.
      Returns:
      This object.
    • onchange

      public HtmlElement onchange(String value)
      onchange attribute.

      Event handler for when the value of a form element changes and loses focus.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onchange("validate(\"field\")")
      • If using double quotes for attributes: onchange("validate('field')")
      Parameters:
      onchange - JavaScript code to execute when the change event occurs.
      Returns:
      This object.
    • onclick

      public HtmlElement onclick(String value)
      onclick attribute.

      Event handler for when the element is clicked.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onclick("alert(\"Hello\")")
      • If using double quotes for attributes: onclick("alert('Hello')")
      Parameters:
      onclick - JavaScript code to execute when the click event occurs.
      Returns:
      This object.
    • oncuechange

      public HtmlElement oncuechange(String value)
      oncuechange attribute.

      Event handler for when a text track cue changes.

      Parameters:
      oncuechange - JavaScript code to execute when the cuechange event occurs.
      Returns:
      This object.
    • ondblclick

      public HtmlElement ondblclick(String value)
      ondblclick attribute.

      Event handler for when the element is double-clicked.

      Parameters:
      ondblclick - JavaScript code to execute when the dblclick event occurs.
      Returns:
      This object.
    • ondurationchange

      ondurationchange attribute.

      Event handler for when the duration of the media changes.

      Parameters:
      ondurationchange - JavaScript code to execute when the durationchange event occurs.
      Returns:
      This object.
    • onemptied

      public HtmlElement onemptied(String value)
      onemptied attribute.

      Event handler for when the media element becomes empty (e.g., network error).

      Parameters:
      onemptied - JavaScript code to execute when the emptied event occurs.
      Returns:
      This object.
    • onended

      public HtmlElement onended(String value)
      onended attribute.

      Event handler for when the media playback reaches the end.

      Parameters:
      onended - JavaScript code to execute when the ended event occurs.
      Returns:
      This object.
    • onerror

      public HtmlElement onerror(String value)
      onerror attribute.

      Event handler for when an error occurs (e.g., failed resource loading).

      Parameters:
      onerror - JavaScript code to execute when the error event occurs.
      Returns:
      This object.
    • onfocus

      public HtmlElement onfocus(String value)
      onfocus attribute.

      Event handler for when the element receives focus.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onfocus("highlight(\"field\")")
      • If using double quotes for attributes: onfocus("highlight('field')")
      Parameters:
      onfocus - JavaScript code to execute when the focus event occurs.
      Returns:
      This object.
    • oninput

      public HtmlElement oninput(String value)
      oninput attribute.

      Event handler for when the value of an input element changes (fires on every keystroke).

      Parameters:
      oninput - JavaScript code to execute when the input event occurs.
      Returns:
      This object.
    • oninvalid

      public HtmlElement oninvalid(String value)
      oninvalid attribute.

      Event handler for when form validation fails.

      Parameters:
      oninvalid - JavaScript code to execute when the invalid event occurs.
      Returns:
      This object.
    • onkeydown

      public HtmlElement onkeydown(String value)
      onkeydown attribute.

      Event handler for when a key is pressed down.

      Parameters:
      onkeydown - JavaScript code to execute when the keydown event occurs.
      Returns:
      This object.
    • onkeypress

      public HtmlElement onkeypress(String value)
      onkeypress attribute.

      Event handler for when a key is pressed (deprecated, use onkeydown instead).

      Parameters:
      onkeypress - JavaScript code to execute when the keypress event occurs.
      Returns:
      This object.
    • onkeyup

      public HtmlElement onkeyup(String value)
      onkeyup attribute.

      Event handler for when a key is released.

      Parameters:
      onkeyup - JavaScript code to execute when the keyup event occurs.
      Returns:
      This object.
    • onload

      public HtmlElement onload(String value)
      onload attribute.

      Event handler for when the element and its resources have finished loading.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onload("init(\"config\")")
      • If using double quotes for attributes: onload("init('config')")
      Parameters:
      onload - JavaScript code to execute when the load event occurs.
      Returns:
      This object.
    • onloadeddata

      onloadeddata attribute.

      Event handler for when the first frame of media has finished loading.

      Parameters:
      onloadeddata - JavaScript code to execute when the loadeddata event occurs.
      Returns:
      This object.
    • onloadedmetadata

      onloadedmetadata attribute.

      Event handler for when metadata (duration, dimensions, etc.) has been loaded.

      Parameters:
      onloadedmetadata - JavaScript code to execute when the loadedmetadata event occurs.
      Returns:
      This object.
    • onloadstart

      public HtmlElement onloadstart(String value)
      onloadstart attribute.

      Event handler for when the browser starts loading the media.

      Parameters:
      onloadstart - JavaScript code to execute when the loadstart event occurs.
      Returns:
      This object.
    • onmousedown

      public HtmlElement onmousedown(String value)
      onmousedown attribute.

      Event handler for when a mouse button is pressed down on the element.

      Parameters:
      onmousedown - JavaScript code to execute when the mousedown event occurs.
      Returns:
      This object.
    • onmouseenter

      onmouseenter attribute.

      Event handler for when the mouse pointer enters the element (does not bubble).

      Parameters:
      onmouseenter - JavaScript code to execute when the mouseenter event occurs.
      Returns:
      This object.
    • onmouseleave

      onmouseleave attribute.

      Event handler for when the mouse pointer leaves the element (does not bubble).

      Parameters:
      onmouseleave - JavaScript code to execute when the mouseleave event occurs.
      Returns:
      This object.
    • onmousemove

      public HtmlElement onmousemove(String value)
      onmousemove attribute.

      Event handler for when the mouse pointer moves over the element.

      Parameters:
      onmousemove - JavaScript code to execute when the mousemove event occurs.
      Returns:
      This object.
    • onmouseout

      public HtmlElement onmouseout(String value)
      onmouseout attribute.

      Event handler for when the mouse pointer moves out of the element (bubbles).

      Parameters:
      onmouseout - JavaScript code to execute when the mouseout event occurs.
      Returns:
      This object.
    • onmouseover

      public HtmlElement onmouseover(String value)
      onmouseover attribute.

      Event handler for when the mouse pointer moves over the element (bubbles).

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onmouseover("showTooltip(\"info\")")
      • If using double quotes for attributes: onmouseover("showTooltip('info')")
      Parameters:
      onmouseover - JavaScript code to execute when the mouseover event occurs.
      Returns:
      This object.
    • onmouseup

      public HtmlElement onmouseup(String value)
      onmouseup attribute.

      Event handler for when a mouse button is released over the element.

      Parameters:
      onmouseup - JavaScript code to execute when the mouseup event occurs.
      Returns:
      This object.
    • onmousewheel

      onmousewheel attribute.

      Event handler for when the mouse wheel is rotated over the element (deprecated, use onwheel).

      Parameters:
      onmousewheel - JavaScript code to execute when the mousewheel event occurs.
      Returns:
      This object.
    • onpause

      public HtmlElement onpause(String value)
      onpause attribute.

      Event handler for when media playback is paused.

      Parameters:
      onpause - JavaScript code to execute when the pause event occurs.
      Returns:
      This object.
    • onplay

      public HtmlElement onplay(String value)
      onplay attribute.

      Event handler for when media playback starts.

      Parameters:
      onplay - JavaScript code to execute when the play event occurs.
      Returns:
      This object.
    • onplaying

      public HtmlElement onplaying(String value)
      onplaying attribute.

      Event handler for when media playback starts after being paused or delayed.

      Parameters:
      onplaying - JavaScript code to execute when the playing event occurs.
      Returns:
      This object.
    • onprogress

      public HtmlElement onprogress(String value)
      onprogress attribute.

      Event handler for when the browser is downloading media data.

      Parameters:
      onprogress - JavaScript code to execute when the progress event occurs.
      Returns:
      This object.
    • onratechange

      onratechange attribute.

      Event handler for when the playback rate of media changes.

      Parameters:
      onratechange - JavaScript code to execute when the ratechange event occurs.
      Returns:
      This object.
    • onreset

      public HtmlElement onreset(String value)
      onreset attribute.

      Event handler for when a form is reset.

      Parameters:
      onreset - JavaScript code to execute when the reset event occurs.
      Returns:
      This object.
    • onresize

      public HtmlElement onresize(String value)
      onresize attribute.

      Event handler for when the element is resized.

      Parameters:
      onresize - JavaScript code to execute when the resize event occurs.
      Returns:
      This object.
    • onscroll

      public HtmlElement onscroll(String value)
      onscroll attribute.

      Event handler for when the element's scrollbar is scrolled.

      Parameters:
      onscroll - JavaScript code to execute when the scroll event occurs.
      Returns:
      This object.
    • onseeked

      public HtmlElement onseeked(String value)
      onseeked attribute.

      Event handler for when a seek operation completes.

      Parameters:
      onseeked - JavaScript code to execute when the seeked event occurs.
      Returns:
      This object.
    • onseeking

      public HtmlElement onseeking(String value)
      onseeking attribute.

      Event handler for when a seek operation begins.

      Parameters:
      onseeking - JavaScript code to execute when the seeking event occurs.
      Returns:
      This object.
    • onselect

      public HtmlElement onselect(String value)
      onselect attribute.

      Event handler for when text is selected in the element.

      Parameters:
      onselect - JavaScript code to execute when the select event occurs.
      Returns:
      This object.
    • onshow

      public HtmlElement onshow(String value)
      onshow attribute.

      Event handler for when a context menu is shown.

      Parameters:
      onshow - JavaScript code to execute when the show event occurs.
      Returns:
      This object.
    • onstalled

      public HtmlElement onstalled(String value)
      onstalled attribute.

      Event handler for when media loading is stalled.

      Parameters:
      onstalled - JavaScript code to execute when the stalled event occurs.
      Returns:
      This object.
    • onsubmit

      public HtmlElement onsubmit(String value)
      onsubmit attribute.

      Event handler for when a form is submitted.

      Note:

      If your HTML serializer is configured to use single quotes for attribute values, you should use double quotes in your JavaScript code, and vice versa. Otherwise, the quotes will be converted to HTML entities. For example:

      • If using single quotes for attributes: onsubmit("return validate(\"form\")")
      • If using double quotes for attributes: onsubmit("return validate('form')")
      Parameters:
      onsubmit - JavaScript code to execute when the submit event occurs.
      Returns:
      This object.
    • onsuspend

      public HtmlElement onsuspend(String value)
      onsuspend attribute.

      Event handler for when media loading is suspended.

      Parameters:
      onsuspend - JavaScript code to execute when the suspend event occurs.
      Returns:
      This object.
    • ontimeupdate

      ontimeupdate attribute.

      Event handler for when the current playback position changes.

      Parameters:
      ontimeupdate - JavaScript code to execute when the timeupdate event occurs.
      Returns:
      This object.
    • ontoggle

      public HtmlElement ontoggle(String value)
      ontoggle attribute.

      Event handler for when a details element is opened or closed.

      Parameters:
      ontoggle - JavaScript code to execute when the toggle event occurs.
      Returns:
      This object.
    • onvolumechange

      onvolumechange attribute.

      Event handler for when the volume of media changes.

      Parameters:
      onvolumechange - JavaScript code to execute when the volumechange event occurs.
      Returns:
      This object.
    • onwaiting

      public HtmlElement onwaiting(String value)
      onwaiting attribute.

      Event handler for when media playback stops to buffer more data.

      Parameters:
      onwaiting - JavaScript code to execute when the waiting event occurs.
      Returns:
      This object.
    • spellcheck

      public HtmlElement spellcheck(Object value)
      spellcheck attribute.

      Indicates whether the element should have its spelling and grammar checked.

      Possible values:

      • "true" - Enable spell checking for this element
      • "false" - Disable spell checking for this element
      Parameters:
      spellcheck - Whether spell checking should be enabled.
      Returns:
      This object.
    • style

      public HtmlElement style(String value)
      style attribute.

      Specifies inline CSS styles for the element. The value should be valid CSS property-value pairs separated by semicolons.

      Parameters:
      style - Inline CSS styles (e.g., "color: red; font-size: 14px;").
      Returns:
      This object.
    • tabindex

      public HtmlElement tabindex(Object value)
      tabindex attribute.

      Specifies the tab order of the element when navigating with the keyboard.

      Possible values:

      • Positive integer - Element is focusable and participates in tab order
      • "0" - Element is focusable but not in tab order
      • Negative integer - Element is not focusable
      Parameters:
      tabindex - The tab order value for keyboard navigation.
      Returns:
      This object.
    • title

      public HtmlElement title(String value)
      title attribute.

      Specifies additional information about the element, typically displayed as a tooltip when the user hovers over the element.

      Parameters:
      title - Tooltip text to display on hover (e.g., "Click to submit form").
      Returns:
      This object.
    • translate

      public HtmlElement translate(Object value)
      translate attribute.

      Specifies whether the element's content should be translated when the page is localized.

      Possible values:

      • "yes" - Content should be translated (default)
      • "no" - Content should not be translated
      Parameters:
      translate - Whether the element content should be translated.
      Returns:
      This object.
    • deminimize

      protected Object deminimize(Object value, String attr)
      If the specified attribute is a boolean, it gets converted to the attribute name if true or null if false.
      Parameters:
      value - The attribute value.
      attr - The attribute name.
      Returns:
      The deminimized value, or the same value if the value wasn't a boolean.
    • toString

      public String toString()
      Overrides:
      toString in class Object