DOM¶
only mutool run
This represents an HTML or an DOM node. It is a helper class intended to access the DOM (Document Object Model) content of a Story object.
Constructors¶
- class DOM()¶
You cannot create instances of this class with the new operator!
Instances of this class are returned by Story.prototype.document().
Instance methods¶
- DOM.prototype.documentElement()¶
Return a DOM for the top level element.
- Returns:
var result = xml.documentElement()
- DOM.prototype.createElement(tag)¶
Create an element with the given tag type, but do not link it into the DOM yet.
- Arguments:
tag (
string) – Tag name to use for element.
- Returns:
var result = xml.createElement("div")
- DOM.prototype.createTextNode(text)¶
Create a text node with the given text contents, but do not link it into the DOM yet.
- Arguments:
text (
string) – Text contents to put into element.
- Returns:
var result = xml.createElement("Hello world!")
- DOM.prototype.find(tag, attribute, value)¶
Find the first element matching the tag, attribute and value. Set either of those to
nullto match anything.- Arguments:
tag (
string) – The tag of the element to look for.attribute (
string) – The attribute of the element to look for.value (
string) – The value of the attribute of the element to look for.
- Returns:
DOM | null
var result = xml.find("tag", "attribute", "value")
- DOM.prototype.findNext(tag, attribute, value)¶
Find the next element matching the tag, attribute and value. Set either of those to
nullto match anything.- Arguments:
tag (
string) – The tag of the element to look for.attribute (
string) – The attribute of the element to look for.value (
string) – The value of the attribute of the element to look for.
- Returns:
DOM | null
var result = xml.findNext("tag", "attribute", "value")
- DOM.prototype.appendChild(dom, childDom)¶
Insert an element as the last child of a parent, unlinking the child from its current position if required.
xml.appendChild(dom, childDom)
- DOM.prototype.insertBefore(dom, elementDom)¶
Insert an element before this element, unlinking the new element from its current position if required.
xml.insertBefore(dom, elementDom)
- DOM.prototype.insertAfter(dom, elementDom)¶
Insert an element after this element, unlinking the new element from its current position if required.
xml.insertAfter(dom, elementDom)
- DOM.prototype.remove()¶
Remove this element from the DOM. The element can be added back elsewhere if required.
var result = xml.remove()
- DOM.prototype.clone()¶
Clone this element (and its children). The clone is not yet linked into the DOM.
- Returns:
var result = xml.clone()
- DOM.prototype.firstChild()¶
Return the first child of the element as a DOM, or
nullif no child exist.- Returns:
DOM | null
var result = xml.firstChild()
- DOM.prototype.parent()¶
Return the parent of the element as a DOM, or
nullif no parent exists.- Returns:
DOM | null
var result = xml.parent()
- DOM.prototype.next()¶
Return the next element as a DOM, or null if no such element exists.
- Returns:
DOM | null
var result = xml.next()
- DOM.prototype.previous()¶
Return the previous element as a DOM, or null if no such element exists.
- Returns:
DOM | null
var result = xml.previous()
- DOM.prototype.addAttribute(attribute, value)¶
Add attribute with the given value, returns the updated element as a DOM.
- Arguments:
attribute (
string) – Desired attribute name.value (
string) – Desired attribute value.
- Returns:
var result = xml.addAttribute("attribute", "value")
- DOM.prototype.removeAttribute(attribute)¶
Remove the specified attribute from the element, returns the updated element as a DOM.
- Arguments:
attribute (
string) – The name of the attribute to remove.
- Returns:
xml.removeAttribute("attribute")
- DOM.prototype.getAttribute(attribute)¶
Return the element’s attribute value as a string, or null if no such attribute exists.
- Arguments:
attribute (
string) – The name of the attribute to look up.
- Returns:
string | null
var result = xml.attribute("attribute")
- DOM.prototype.getAttributes()¶
Returns a dictionary object with properties and their values corresponding to the element’s attributes and their values.
- Returns:
Object
var dict = xml.getAttributes()
- DOM.prototype.getText()¶
only mutool run
Returns the text contents of the node.
- Returns:
string | null
var text = xml.getText()
- DOM.prototype.getTag()¶
only mutool run
Returns the tag name for the node.
- Returns:
string | null
var text = xml.getTag()