Class HtmlTag


public final class HtmlTag extends HtmlNode
An HTML element with attributes and children. Void elements such as <img> are written without closing tag.
  • Method Details

    • name

      public String name()
      Description copied from class: HtmlNode
      Returns the name of the HTML tag or an empty string for text nodes.
      Specified by:
      name in class HtmlNode
      Returns:
      the name of the HTML tag or an empty string for text nodes
    • setName

      public void setName(String name)
    • attribute

      public @Nullable String attribute(String name)
      Description copied from class: HtmlNode
      Returns the value of the attribute, or null if it isn't set or has no value.
      Specified by:
      attribute in class HtmlNode
      Returns:
      the value of the attribute, or null if it isn't set or has no value
    • setAttribute

      public HtmlTag setAttribute(String name, @Nullable String value)
      Description copied from class: HtmlNode
      Sets an attribute. A null value writes the attribute without a value (i.e. <details open>).
      Specified by:
      setAttribute in class HtmlNode
    • setClassName

      public HtmlTag setClassName(String className)
    • children

      public List<HtmlNode> children()
      Specified by:
      children in class HtmlNode
    • append

      public HtmlTag append(HtmlFragment fragment)
    • append

      public HtmlTag append(String text)
    • append

      public HtmlTag append(HtmlNode node)
    • setStyles

      public HtmlTag setStyles(Map<String,String> styles)
      Replaces the style attribute with the given CSS properties.
    • outerHtml

      public String outerHtml()
      Description copied from class: HtmlNode
      Returns the HTML of this node and its descendants.
      Specified by:
      outerHtml in class HtmlNode
      Returns:
      the HTML of this node and its descendants
    • textContent

      public String textContent()
      Description copied from class: HtmlNode
      Returns the text of this node and its descendants, without markup.
      Specified by:
      textContent in class HtmlNode
      Returns:
      the text of this node and its descendants, without markup