Each callback function receives an object that represents the selected HTML tags or other relevant information. The object is also known as an argument. This topic describes arguments such as Element, TextChunk, and Comments.

Note
  • All arguments must be passed into callback functions. If the methods or properties of an argument are invoked outside of a callback function, JavaScript exceptions are thrown. To avoid this problem, you can pass the desired arguments into other JavaScript objects or data structures.
  • The option in the methods described in this topic represents an object. The HTML property in the object can be set to true or false. A value of true indicates HTML content. A value of false indicates text content. If you set the HTML property to false, HTMLStream calls the html encoding/escaping function.

Element

  • Definition

    This object is returned when the Element callback function is called. This object represents the selected HTML tags.

  • Properties
    • tagName(string): the name of the tag.
    • attributes(iterator): returns an iterator that locates all attributes in the format of [name, value].
    • removed(bool): specifies whether to delete the specified element. This property is read-only. You can call the remove() method to delete a specified element. In most cases, you need to set this property to ignore an element that has already been deleted.
    • namespaceURI: specifies the namespace URI of an element, for example, the SVG or Script element. This property is read-only.
  • Methods
    • Modify properties
      • getAttribute(name): queries a property name of a specified element.
      • setAttribute(name, value): sets a property name for a specified element and modifies the property name of a specified element.
      • hasAttribute(name): queries whether a property name exists in a specified element.
      • removeAttribute(name): deletes a property name from a specified element.
      Note Both the key and value of a property name must be of STRING type.
    • Modify content
      • before(data, option): inserts content before the specified element (element tag).
      • after(data, option): inserts content after the specified element (element tag).
      • prepend(data, option): inserts content before the element content (after the opening tag of the element). Example: <div>(prepend) |aaaa|(append)</div>.
      • append(data, option): inserts content after the element content (before the closing tag of the element). Example: <div>(prepend) |aaaa|(append)</div>.
      • replace(data, option): replaces the entire element, including the tags and nested tags.
      • setInnerContent(data, option): specifies the element content and leaves the tags and properties unchanged.
      • remove(): deletes the specified element. After the element is deleted, the value of the removed property changes to true.
      • removeAndKeepContent(): deletes tags and properties of the specified element and retains the content.

TextChunk

  • Definition

    This object is returned when the Text callback function is called. This object represents a chunk of the selected HTML text.

  • Properties
    • removed(bool): specifies whether to delete the specified element. This property is read-only. You can call the remove() method to delete a specified element. In most cases, you need to set this property to ignore an element that has already been deleted.
    • text(string): specifies the text content. This property is read-only. The text may be a chunk of text. If the string is empty, it indicates that the last chunk of text is returned. In this case, you can merge all chunks of text.
    • lastInTextNode(bool): indicates whether it is the last chunk of text. This property is read-only. If the value of this property is true, the text property returns an empty string.
  • Methods
    Modify content
    • before(data, option): inserts content before the specified element (element tag).
    • after(data, option): inserts content after the specified element (element tag).
    • replace(data, option): replaces the entire element, including the tags and nested tags.
    • remove(): deletes the specified element. After the element is deleted, the value of the removed property changes to true.

Comments

  • Definition

    This object is returned when the Comments callback function is called. This object represents the comments in the selected HTML content.

  • Properties
    • removed(bool): specifies whether to delete the specified element. This property is read-only. You can call the remove() method to delete a specified element. In most cases, you need to set this property to ignore an element that has already been deleted.
    • text(string): specifies the existing comments or the comments to overwrite the existing ones. This property is readable and writable.
  • Methods
    Modify content
    • before(data, option): inserts content before the specified element (element tag).
    • after(data, option): inserts content after the specified element (element tag).
    • replace(data, option): replaces the entire element, including the tags and nested tags.
    • remove(): deletes the specified element. After the element is deleted, the value of the removed property changes to true.

Doctype

  • Definition

    This object is returned when the document type declaration (DOCTYPE) callback function is called. This object represents the DOCTYPE of the selected HTML content.

  • Properties
    • name(string): specifies the DOCTYPE name. This property is ready-only.
    • publicId(string): returns a public identifier. If no public identifier exists, a value of null is returned. This property is read-only.
    • systemId(string): returns a system identifier. If no system identifier exists, a value of null is returned. This property is read-only.

Docend

  • Definition

    This object is returned when the Decend callback function is called. This object represents the end of an HTML document.

  • Methods

    append(string, option): appends content to the end of the HTML document.