1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
.. default-domain:: js
.. highlight:: javascript
DOM
===
|only_mutool|
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
|no_new|
Instances of this class are returned by `Story.prototype.document()`.
Instance methods
----------------
.. method:: DOM.prototype.body()
Return a DOM for the body element.
:returns: `DOM`
.. code-block::
var result = xml.body()
.. method:: DOM.prototype.documentElement()
Return a DOM for the top level element.
:returns: `DOM`
.. code-block::
var result = xml.documentElement()
.. method:: DOM.prototype.createElement(tag)
Create an element with the given tag type, but do not link it into
the `DOM` yet.
:param string tag: Tag name to use for element.
:returns: `DOM`
.. code-block::
var result = xml.createElement("div")
.. method:: DOM.prototype.createTextNode(text)
Create a text node with the given text contents, but do not link
it into the `DOM` yet.
:param string text: Text contents to put into element.
:returns: `DOM`
.. code-block::
var result = xml.createElement("Hello world!")
.. method:: DOM.prototype.find(tag, attribute, value)
Find the first element matching the tag, attribute and value. Set
either of those to ``null`` to match anything.
:param string tag: The tag of the element to look for.
:param string attribute: The attribute of the element to look for.
:param string value: The value of the attribute of the element to look for.
:returns: `DOM` | null
.. code-block::
var result = xml.find("tag", "attribute", "value")
.. method:: DOM.prototype.findNext(tag, attribute, value)
Find the next element matching the tag, attribute and value. Set either
of those to ``null`` to match anything.
:param string tag: The tag of the element to look for.
:param string attribute: The attribute of the element to look for.
:param string value: The value of the attribute of the element to look for.
:returns: `DOM` | null
.. code-block::
var result = xml.findNext("tag", "attribute", "value")
.. method:: DOM.prototype.appendChild(dom, childDom)
Insert an element as the last child of a parent, unlinking the child
from its current position if required.
:param DOM dom: The DOM that will be parent.
:param DOM childDom: The DOM that will be a child.
.. code-block::
xml.appendChild(dom, childDom)
.. method:: DOM.prototype.insertBefore(dom, elementDom)
Insert an element before this element, unlinking the new element
from its current position if required.
:param DOM dom: The reference DOM.
:param DOM elementDom: The DOM that will be inserted before.
.. code-block::
xml.insertBefore(dom, elementDom)
.. method:: DOM.prototype.insertAfter(dom, elementDom)
Insert an element after this element, unlinking the new element
from its current position if required.
:param DOM dom: The reference DOM.
:param DOM elementDom: The DOM that will be inserted after.
.. code-block::
xml.insertAfter(dom, elementDom)
.. method:: DOM.prototype.remove()
Remove this element from the `DOM`. The element can be
added back elsewhere if required.
.. code-block::
var result = xml.remove()
.. method:: DOM.prototype.clone()
Clone this element (and its children). The clone is not yet linked
into the `DOM`.
:returns: `DOM`
.. code-block::
var result = xml.clone()
.. method:: DOM.prototype.firstChild()
Return the first child of the element as a `DOM`, or
``null`` if no child exist.
:returns: `DOM` | null
.. code-block::
var result = xml.firstChild()
.. method:: DOM.prototype.parent()
Return the parent of the element as a `DOM`, or ``null``
if no parent exists.
:returns: `DOM` | null
.. code-block::
var result = xml.parent()
.. method:: DOM.prototype.next()
Return the next element as a `DOM`, or null if no such
element exists.
:returns: `DOM` | null
.. code-block::
var result = xml.next()
.. method:: DOM.prototype.previous()
Return the previous element as a `DOM`, or null if no such
element exists.
:returns: `DOM` | null
.. code-block::
var result = xml.previous()
.. method:: DOM.prototype.addAttribute(attribute, value)
Add attribute with the given value, returns the updated element as
a DOM.
:param string attribute: Desired attribute name.
:param string value: Desired attribute value.
:returns: `DOM`
.. code-block::
var result = xml.addAttribute("attribute", "value")
.. method:: DOM.prototype.removeAttribute(attribute)
Remove the specified attribute from the element, returns the
updated element as a DOM.
:param string attribute: The name of the attribute to remove.
:returns: `DOM`
.. code-block::
xml.removeAttribute("attribute")
.. method:: DOM.prototype.getAttribute(attribute)
Return the element's attribute value as a string, or null if no
such attribute exists.
:param string attribute: The name of the attribute to look up.
:returns: string | null
.. code-block::
var result = xml.attribute("attribute")
.. method:: DOM.prototype.getAttributes()
Returns a dictionary object with properties and their values
corresponding to the element's attributes and their values.
:returns: Object
.. code-block::
var dict = xml.getAttributes()
.. method:: DOM.prototype.getText()
|only_mutool|
Returns the text contents of the node.
:returns: string | null
.. code-block::
var text = xml.getText()
.. method:: DOM.prototype.getTag()
|only_mutool|
Returns the tag name for the node.
:returns: string | null
.. code-block::
var text = xml.getTag()
|