Class HtmlElement<SELF extends HtmlElement<SELF>>

java.lang.Object
org.apache.juneau.bean.html5.HtmlElement<SELF>
Type Parameters:
SELF - The self type for fluent setters.
Direct Known Subclasses:
HtmlElementContainer, HtmlElementMixed, HtmlElementRawText, HtmlElementText, HtmlElementVoid

@Html(format=XML) public abstract class HtmlElement<SELF extends HtmlElement<SELF>> 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

    • self

      protected final SELF self()
    • class_

      public SELF 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:
      value - Space-separated CSS class names (e.g., "btn btn-primary"). Can be null to unset the attribute.
      Returns:
      This object.
    • accesskey

      public SELF 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:
      value - The keyboard shortcut character (e.g., "a", "1"). Can be null to unset the attribute.
      Returns:
      This object.
    • attr

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

      public SELF 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. Can be null, in which case the attribute is added with a null value (unlike attr(String, Object), the key is not removed).
      Returns:
      This object.
    • contenteditable

      public SELF contenteditable(Object value)
      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:
      value - The editability state of the element. Can be null to unset the attribute.
      Returns:
      This object.
    • dir

      public SELF 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:
      value - The text direction for the element. Can be null to unset the attribute.
      Returns:
      This object.
    • 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 BasicConverter for a list of supported conversion types.
      key - The attribute name.
      Returns:
      The attribute value, or null if the named attribute does not exist.
      Throws:
      InvalidConversionException - If the attribute value cannot be converted to the specified type.
    • 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.
    • getAttrs

      The attributes of this element.
      Returns:
      The attributes of this element, or null if no attributes are set.
    • hidden

      public SELF 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:
      value - The new value for this attribute. Typically a Boolean or String. Can be null to unset the attribute.
      Returns:
      This object.
    • id

      public SELF 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:
      value - A unique identifier for the element (e.g., "header", "main-content"). Can be null to unset the attribute.
      Returns:
      This object.
    • lang

      public SELF 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:
      value - A language tag (e.g., "en", "en-US", "es", "fr-CA"). Can be null to unset the attribute.
      Returns:
      This object.
    • onabort

      public SELF onabort(String value)
      onabort attribute.

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

      Parameters:
      value - JavaScript code to execute when the abort event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onblur

      public SELF 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:
      value - JavaScript code to execute when the element loses focus. Can be null to unset the attribute.
      Returns:
      This object.
    • oncancel

      public SELF oncancel(String value)
      oncancel attribute.

      Event handler for when a dialog is cancelled.

      Parameters:
      value - JavaScript code to execute when the cancel event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • oncanplay

      public SELF oncanplay(String value)
      oncanplay attribute.

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

      Parameters:
      value - JavaScript code to execute when the canplay event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • oncanplaythrough

      public SELF oncanplaythrough(String value)
      oncanplaythrough attribute.

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

      Parameters:
      value - JavaScript code to execute when the canplaythrough event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onchange

      public SELF 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:
      value - JavaScript code to execute when the change event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onclick

      public SELF 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:
      value - JavaScript code to execute when the click event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • oncuechange

      public SELF oncuechange(String value)
      oncuechange attribute.

      Event handler for when a text track cue changes.

      Parameters:
      value - JavaScript code to execute when the cuechange event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • ondblclick

      public SELF ondblclick(String value)
      ondblclick attribute.

      Event handler for when the element is double-clicked.

      Parameters:
      value - JavaScript code to execute when the dblclick event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • ondurationchange

      public SELF ondurationchange(String value)
      ondurationchange attribute.

      Event handler for when the duration of the media changes.

      Parameters:
      value - JavaScript code to execute when the durationchange event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onemptied

      public SELF onemptied(String value)
      onemptied attribute.

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

      Parameters:
      value - JavaScript code to execute when the emptied event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onended

      public SELF onended(String value)
      onended attribute.

      Event handler for when the media playback reaches the end.

      Parameters:
      value - JavaScript code to execute when the ended event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onerror

      public SELF onerror(String value)
      onerror attribute.

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

      Parameters:
      value - JavaScript code to execute when the error event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onfocus

      public SELF 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:
      value - JavaScript code to execute when the focus event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • oninput

      public SELF oninput(String value)
      oninput attribute.

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

      Parameters:
      value - JavaScript code to execute when the input event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • oninvalid

      public SELF oninvalid(String value)
      oninvalid attribute.

      Event handler for when form validation fails.

      Parameters:
      value - JavaScript code to execute when the invalid event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onkeydown

      public SELF onkeydown(String value)
      onkeydown attribute.

      Event handler for when a key is pressed down.

      Parameters:
      value - JavaScript code to execute when the keydown event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onkeypress

      public SELF onkeypress(String value)
      onkeypress attribute.

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

      Parameters:
      value - JavaScript code to execute when the keypress event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onkeyup

      public SELF onkeyup(String value)
      onkeyup attribute.

      Event handler for when a key is released.

      Parameters:
      value - JavaScript code to execute when the keyup event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onload

      public SELF 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:
      value - JavaScript code to execute when the load event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onloadeddata

      public SELF onloadeddata(String value)
      onloadeddata attribute.

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

      Parameters:
      value - JavaScript code to execute when the loadeddata event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onloadedmetadata

      public SELF onloadedmetadata(String value)
      onloadedmetadata attribute.

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

      Parameters:
      value - JavaScript code to execute when the loadedmetadata event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onloadstart

      public SELF onloadstart(String value)
      onloadstart attribute.

      Event handler for when the browser starts loading the media.

      Parameters:
      value - JavaScript code to execute when the loadstart event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onmousedown

      public SELF onmousedown(String value)
      onmousedown attribute.

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

      Parameters:
      value - JavaScript code to execute when the mousedown event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onmouseenter

      public SELF onmouseenter(String value)
      onmouseenter attribute.

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

      Parameters:
      value - JavaScript code to execute when the mouseenter event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onmouseleave

      public SELF onmouseleave(String value)
      onmouseleave attribute.

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

      Parameters:
      value - JavaScript code to execute when the mouseleave event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onmousemove

      public SELF onmousemove(String value)
      onmousemove attribute.

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

      Parameters:
      value - JavaScript code to execute when the mousemove event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onmouseout

      public SELF onmouseout(String value)
      onmouseout attribute.

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

      Parameters:
      value - JavaScript code to execute when the mouseout event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onmouseover

      public SELF 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:
      value - JavaScript code to execute when the mouseover event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onmouseup

      public SELF onmouseup(String value)
      onmouseup attribute.

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

      Parameters:
      value - JavaScript code to execute when the mouseup event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onmousewheel

      public SELF onmousewheel(String value)
      onmousewheel attribute.

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

      Parameters:
      value - JavaScript code to execute when the mousewheel event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onpause

      public SELF onpause(String value)
      onpause attribute.

      Event handler for when media playback is paused.

      Parameters:
      value - JavaScript code to execute when the pause event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onplay

      public SELF onplay(String value)
      onplay attribute.

      Event handler for when media playback starts.

      Parameters:
      value - JavaScript code to execute when the play event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onplaying

      public SELF onplaying(String value)
      onplaying attribute.

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

      Parameters:
      value - JavaScript code to execute when the playing event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onprogress

      public SELF onprogress(String value)
      onprogress attribute.

      Event handler for when the browser is downloading media data.

      Parameters:
      value - JavaScript code to execute when the progress event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onratechange

      public SELF onratechange(String value)
      onratechange attribute.

      Event handler for when the playback rate of media changes.

      Parameters:
      value - JavaScript code to execute when the ratechange event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onreset

      public SELF onreset(String value)
      onreset attribute.

      Event handler for when a form is reset.

      Parameters:
      value - JavaScript code to execute when the reset event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onresize

      public SELF onresize(String value)
      onresize attribute.

      Event handler for when the element is resized.

      Parameters:
      value - JavaScript code to execute when the resize event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onscroll

      public SELF onscroll(String value)
      onscroll attribute.

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

      Parameters:
      value - JavaScript code to execute when the scroll event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onseeked

      public SELF onseeked(String value)
      onseeked attribute.

      Event handler for when a seek operation completes.

      Parameters:
      value - JavaScript code to execute when the seeked event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onseeking

      public SELF onseeking(String value)
      onseeking attribute.

      Event handler for when a seek operation begins.

      Parameters:
      value - JavaScript code to execute when the seeking event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onselect

      public SELF onselect(String value)
      onselect attribute.

      Event handler for when text is selected in the element.

      Parameters:
      value - JavaScript code to execute when the select event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onshow

      public SELF onshow(String value)
      onshow attribute.

      Event handler for when a context menu is shown.

      Parameters:
      value - JavaScript code to execute when the show event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onstalled

      public SELF onstalled(String value)
      onstalled attribute.

      Event handler for when media loading is stalled.

      Parameters:
      value - JavaScript code to execute when the stalled event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onsubmit

      public SELF 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:
      value - JavaScript code to execute when the submit event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onsuspend

      public SELF onsuspend(String value)
      onsuspend attribute.

      Event handler for when media loading is suspended.

      Parameters:
      value - JavaScript code to execute when the suspend event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • ontimeupdate

      public SELF ontimeupdate(String value)
      ontimeupdate attribute.

      Event handler for when the current playback position changes.

      Parameters:
      value - JavaScript code to execute when the timeupdate event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • ontoggle

      public SELF ontoggle(String value)
      ontoggle attribute.

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

      Parameters:
      value - JavaScript code to execute when the toggle event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onvolumechange

      public SELF onvolumechange(String value)
      onvolumechange attribute.

      Event handler for when the volume of media changes.

      Parameters:
      value - JavaScript code to execute when the volumechange event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • onwaiting

      public SELF onwaiting(String value)
      onwaiting attribute.

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

      Parameters:
      value - JavaScript code to execute when the waiting event occurs. Can be null to unset the attribute.
      Returns:
      This object.
    • setAttrs

      @BeanProp("a") public SELF setAttrs(Map<String,Object> value)
      Sets the attributes for this element.
      Parameters:
      value - The new attributes for this element. Can be null to clear all attributes.
      Returns:
      This object.
    • spellcheck

      public SELF 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:
      value - Whether spell checking should be enabled. Can be null to unset the attribute.
      Returns:
      This object.
    • style

      public SELF 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:
      value - Inline CSS styles (e.g., "color: red; font-size: 14px;"). Can be null to unset the attribute.
      Returns:
      This object.
    • tabindex

      public SELF 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:
      value - The tab order value for keyboard navigation. Can be null to unset the attribute.
      Returns:
      This object.
    • title

      public SELF title(String value)
      title attribute.

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

      Parameters:
      value - Tooltip text to display on hover (e.g., "Click to submit form"). Can be null to unset the attribute.
      Returns:
      This object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • translate

      public SELF 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:
      value - Whether the element content should be translated. Can be null to unset the attribute.
      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. Can be null (returned as-is, since null is not a Boolean).
      attr - The attribute name.
      Returns:
      The deminimized value, or the same value if the value wasn't a boolean, or null if the value was a boolean false.