Element
Represents an HTML element encountered during rewriting. Passed to the callback registered via HTMLRewritingStream.onElement.
Properties
The CSS selector that matched this element.
The tag name of this element.
Methods
after
View sourceInserts content after the element's closing tag.
Parameters
- content: string
HTML or text to insert
- options: ElementRewriterOptionsoptional
Optional rewriting options
Returns
append
View sourceInserts content at the end of the element's children.
Parameters
- content: string
HTML or text to append
- options: ElementRewriterOptionsoptional
Optional rewriting options
Returns
before
View sourceInserts content before the element's opening tag.
Parameters
- content: string
HTML or text to insert
- options: ElementRewriterOptionsoptional
Optional rewriting options
Returns
getAttribute
View sourcegetAttribute(name: string): string | nullGets the value of an attribute.
Parameters
- name: string
Attribute name
Returns
The attribute value, or null if the attribute is not present.
prepend
View sourceInserts content at the beginning of the element's children.
Parameters
- content: string
HTML or text to prepend
- options: ElementRewriterOptionsoptional
Optional rewriting options
Returns
removeAttribute
View sourceremoveAttribute(name: string): voidRemoves an attribute from the element.
Parameters
- name: string
Attribute name
Returns
replaceChildren
View sourceReplaces the element's children with new content, keeping the element's tags.
Parameters
- content: string
Replacement HTML or text
- options: ElementRewriterOptionsoptional
Optional rewriting options
Returns
replaceWith
View sourceReplaces the element and its children with new content.
Parameters
- content: string
Replacement HTML or text
- options: ElementRewriterOptionsoptional
Optional rewriting options
Returns
setAttribute
View sourcesetAttribute(name: string, value: string): voidSets an attribute on the element. If the attribute already exists, its value is updated.
Parameters
- name: string
Attribute name
- value: string
Attribute value
Returns