Interface Element

All Superinterfaces:
org.teavm.jso.JSObject

public interface Element extends org.teavm.jso.JSObject
An element the rewriter has reached. Use it inside the handler call that received it.

Content is a string: text, escaped, or raw HTML with ContentOptions.html(). The platform also takes a Response or a ReadableStream; those are not wrapped here.

Since:
1.0.3
  • Method Details

    • getTagName

      String getTagName()
      Returns the tag name, such as h1.
      Returns:
      the tag name, such as h1
    • setTagName

      void setTagName(String name)
      Renames the tag.
      Parameters:
      name - the new name
    • isRemoved

      boolean isRemoved()
      Returns whether an earlier handler already removed or replaced this element.
      Returns:
      whether an earlier handler already removed or replaced this element
    • getNamespaceURI

      String getNamespaceURI()
      Returns the namespace URI, such as http://www.w3.org/1999/xhtml.
      Returns:
      the namespace URI, such as http://www.w3.org/1999/xhtml
    • attributes

      default Map<String,String> attributes()
      Returns the attributes in document order, copied at the call.
      Returns:
      the attributes in document order, copied at the call
    • getAttribute

      String getAttribute(String name)
      Reads an attribute.
      Parameters:
      name - the attribute name
      Returns:
      the value, or null when the element has none
    • hasAttribute

      boolean hasAttribute(String name)
      Tests for an attribute.
      Parameters:
      name - the attribute name
      Returns:
      whether the element has it
    • setAttribute

      Element setAttribute(String name, String value)
      Sets an attribute, adding it when the element has none.
      Parameters:
      name - the attribute name
      value - the value
      Returns:
      this element
    • removeAttribute

      Element removeAttribute(String name)
      Removes an attribute.
      Parameters:
      name - the attribute name
      Returns:
      this element
    • before

      Element before(String content)
      Inserts text before the element.
      Parameters:
      content - the text, escaped
      Returns:
      this element
    • before

      Element before(String content, ContentOptions options)
      Inserts content before the element.
      Parameters:
      content - the content
      options - how to read it
      Returns:
      this element
    • after

      Element after(String content)
      Inserts text after the element.
      Parameters:
      content - the text, escaped
      Returns:
      this element
    • after

      Element after(String content, ContentOptions options)
      Inserts content after the element.
      Parameters:
      content - the content
      options - how to read it
      Returns:
      this element
    • prepend

      Element prepend(String content)
      Inserts text right after the start tag.
      Parameters:
      content - the text, escaped
      Returns:
      this element
    • prepend

      Element prepend(String content, ContentOptions options)
      Inserts content right after the start tag.
      Parameters:
      content - the content
      options - how to read it
      Returns:
      this element
    • append

      Element append(String content)
      Inserts text right before the end tag.
      Parameters:
      content - the text, escaped
      Returns:
      this element
    • append

      Element append(String content, ContentOptions options)
      Inserts content right before the end tag.
      Parameters:
      content - the content
      options - how to read it
      Returns:
      this element
    • replace

      Element replace(String content)
      Replaces the element, with its content, by text.
      Parameters:
      content - the text, escaped
      Returns:
      this element
    • replace

      Element replace(String content, ContentOptions options)
      Replaces the element, with its content, by other content.
      Parameters:
      content - the content
      options - how to read it
      Returns:
      this element
    • setInnerContent

      Element setInnerContent(String content)
      Replaces what is inside the element by text.
      Parameters:
      content - the text, escaped
      Returns:
      this element
    • setInnerContent

      Element setInnerContent(String content, ContentOptions options)
      Replaces what is inside the element by other content.
      Parameters:
      content - the content
      options - how to read it
      Returns:
      this element
    • remove

      Element remove()
      Removes the element with everything inside it.
      Returns:
      this element
    • removeAndKeepContent

      Element removeAndKeepContent()
      Removes the start and end tags and keeps what is inside.
      Returns:
      this element
    • onEndTag

      default void onEndTag(EndTagHandler handler)
      Calls a handler when the element's end tag is reached.
      Parameters:
      handler - the handler