dom¶
The DOM is gradually evolving…
To use the DOM either reference your root ‘html’ node or import the dom modules global ‘document’
# access the document via the html tag
mydom = html()
# mydom.getElementbyID...
# or by importing the document global
from domonic.dom import document
# document.createElement...
print(document)
The last ‘html()’ created will always be the ‘document’. You can set it manually but it needs to be a Document instance. Before a ‘html’ class is created it is just an empty document so that static methods can be available.
Remember python globals are only to that module (unlike other langs). so you will have to import document explicitly when you need it (per method call after setting it). i.e
print(document)
d = html(body("Hello"))
print(document) # no change
print('body1', d.doctype)
print('body2', domonic.dom.document.doctype)
print('body3', document.doctype)
from domonic.dom import document # re-import to get the updated document
print('body4', document.doctype)
notice how before it was imported it was still just a class not an instance.
So in most cases just use your own root node and not document as it will be the only one that will be updated unless you import after any html node creation. The global is for when you need to access the document from a different module(file)
createElement¶
Here’s an exmaple of creating your own elements using the DOM API
from domonic.dom import *
from domonic.dom import document
site = html()
el = document.createElement('myelement')
site.appendChild(el)
print(site)
querySelectorAll¶
querySelectorAll and querySelector are useful for finding elements in the DOM.
mysite.querySelectorAll('button')
mysite.querySelectorAll('.fa-twitter')
mysite.querySelectorAll("a[rel=nofollow]")
mysite.querySelectorAll("a[href='#services']")
mysite.querySelectorAll("a[href$='technology']")
somelinks = mysite.querySelectorAll("a[href*='twitter']")
for l in somelinks:
print(l.href)
To use the DOM either reference your root ‘html’ node or import the dom modules global ‘document’
# access the document via the html tag
mydom = html()
# mydom.getElementbyID...
# or by importing the document global
from domonic.dom import document
# document.createElement...
print(document)
The last ‘html()’ you created will always be the ‘document’. You can also set it manually but it needs to ne a Document instance. Before a ‘html’ class is created there is an empty document so that static methods can be available.
a note on globals Remember python globals are only to that module (unlike other langs). So you will have to import document explicitly when you need it (per method call)
See the examples folder for other uses of a python virtual DOM.
DOMConfig¶
DOMConfig is for setting some render options on the dom.
i.e. here’s we set all the current flags to be opposite their default…
from domonic.html import *
from domonic.dom import DOMConfig
DOMConfig.GLOBAL_AUTOESCAPE = True
DOMConfig.HTMX_ENABLED = True
DOMConfig.RENDER_OPTIONAL_CLOSING_TAGS = False
print(html(head(),body(div(h1('heading'),div(button('hi & hack',_get='/get_hi'))))))
# <html><head></head><body><div><h1>heading</h1><div><button data-hx-get="/get_hi">hi & hack</button></div></div></body></html>
The full list of available DOM methods are listed below…
domonic.dom¶
The DOM represents a document with a logical tree. https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model
- class domonic.dom.CDATASection(data)[source]
- class domonic.dom.CharacterData(*args, **kwargs)[source]
The CharacterData abstract interface represents a Node object that contains characters. This is an abstract interface, meaning there aren’t any objects of type CharacterData: it is implemented by other interfaces like Text, Comment, or ProcessingInstruction, which aren’t abstract.
- after(newChild)
Inserts a newChild node immediately after this ChildNode.
- appendData(data)[source]
Appends the given DOMString to the CharacterData.data string; when this method returns, data contains the concatenated DOMString.
- before(newChild)
Inserts a newChild node immediately before this ChildNode.
- deleteData(offset: int, count: int)[source]
Removes the specified amount of characters, starting at the specified offset, from the CharacterData.data string; when this method returns, data contains the shortened DOMString.
- insertData(offset: int, data)[source]
Inserts the specified characters, at the specified offset, in the CharacterData.data string; when this method returns, data contains the modified DOMString.
- property nextElementSibling
Returns the next element at the same node tree level
- property previousElementSibling
returns the Element immediately prior to the specified one in its parent’s children list, or None if the specified element is the first one in the list.
- remove()
Removes this ChildNode from the children list of its parent.
- replaceData(offset: int, count: int, data)[source]
Replaces the specified amount of characters, starting at the specified offset, with the specified DOMString; when this method returns, data contains the modified DOMString.
- replaceWith(newChild)
Replaces this ChildNode with a new one.
- class domonic.dom.ChildNode(*args, **kwargs)[source]
not tested yet
- after(newChild)[source]
Inserts a newChild node immediately after this ChildNode.
- before(newChild)[source]
Inserts a newChild node immediately before this ChildNode.
- remove()[source]
Removes this ChildNode from the children list of its parent.
- replaceWith(newChild)[source]
Replaces this ChildNode with a new one.
- class domonic.dom.Comment(data)[source]
- class domonic.dom.DOMConfig[source]
DOMConfig: Not to be confused with the obsolete DOMConfiguration.
This class is used to set some global rules for our dom.
GLOBAL_AUTOESCAPE - If this is set to True, then all text nodes will be automatically escaped. HTML5_MODE - doesn’t render close tags on certain elements HTMX_ENABLED - inludes htmx attributes into domonic for quicker notation
- exception domonic.dom.DOMException(code, message: Optional[str] = None)[source]
The DOMException interface represents an anormal event related to the DOM.
- class domonic.dom.DOMPoint(x: float, y: float, z: float = 0, w: float = 1)[source]
The DOMPoint interface represents a point specified by x and y coordinates.
- class domonic.dom.DOMPointReadOnly(x: float, y: float, z: float = 0, w: float = 1)[source]
The DOMPointReadOnly interface represents a point specified by x and y coordinates.
- class domonic.dom.DOMQuad(p1, p2, p3, p4)[source]
The DOMQuad interface represents a quadrilateral on the plane with its four corners represented as Cartesian coordinates.
- class domonic.dom.DOMStringMap(*args, **kwargs)[source]
TODO - not tested yet TODO - make this like a dict
- class domonic.dom.DOMTimeStamp(value)[source]
The DOMTimeStamp interface represents a numeric value which represents the number of milliseconds since the epoch.
- class domonic.dom.DOMTokenList(element: Node)[source]
DOMTokenList represents a set of space-separated tokens.
- add(*args)[source]
Adds the given tokens to the list
- remove(*args)[source]
Removes the given tokens from the list
- toString() str [source]
Returns a string containing all tokens in the list, with spaces separating each token
- toggle(token, force=None)[source]
If force is not given, removes token from list if present, otherwise adds token to list. If force is true, adds token to list, and if force is false, removes token from list if present.
- class domonic.dom.Document(*args, **kwargs)[source]
The Document interface represents the entire HTML or XML document.
- property anchors
[get the anchors in the document]
- property applets
Returns a collection of all <applet> elements in the document
- property body
Returns the <body> element in the document
- property characterSet
Returns the character encoding for the document
- property charset
Use characterSet instead.
- Type
Returns the character encoding for the document. Deprecated
- close()[source]
Closes the output stream previously opened with document.open()
- static createAttribute(name)[source]
Creates an attribute node
- static createCDATASection(data)[source]
Creates a CDATASection node with the specified data
- static createComment(message)[source]
Creates a Comment node with the specified text
- static createDocumentFragment(*args)[source]
Creates an empty DocumentFragment node if not content passed. I added args as optional to pass content
- static createElementNS(namespaceURI, qualifiedName, options=None)[source]
Creates an element with the specified namespace URI and qualified name.
- static createEntityReference(name)[source]
Creates an EntityReference node with the specified name
- static createEvent(event_type=None)[source]
[Creates a new event]
- static createExpression(xpath, nsResolver)[source]
Creates an XPathExpression object for the given XPath string.
- static createNodeIterator(root, whatToShow=None, filter=None)[source]
Creates a NodeIterator that can be used to traverse the document tree or subtree under root.
- static createProcessingInstruction(target, data)[source]
Creates a ProcessingInstruction node with the specified target and data
- static createRange()[source]
Creates a Range
- static createTextNode(text)[source]
[Creates a Text node with the specified text.
- static createTreeWalker(root, whatToShow=None, filter=None, entityReferenceExpansion=None)[source]
[creates a TreeWalker object]
- Parameters
- Returns
[a new TreeWalker object]
- Return type
[type]
- property doctype
Returns the Document Type Declaration associated with the document
- domConfig()[source]
Returns the DOMConfig which has settings for how html content is rendered
- domain()[source]
Returns the domain name of the server that loaded the document
- elementFromPoint(x, y)[source]
Returns the topmost element at the specified coordinates.
- elementsFromPoint(x, y)[source]
Returns an array of all elements at the specified coordinates.
- property embeds
[Returns a collection of all <embed> elements the document]
- Returns
[a collection of all <embed> elements the document]
- Return type
[type]
- evaluate(xpathExpression: str, contextNode: Optional[Node] = None, namespaceResolver=None, resultType=7, result=None)[source]
Evaluates an XPath expression and returns the result.
- property forms
Returns a collection of all <form> elements in the document
- fullscreenElement()[source]
Returns the current element that is displayed in fullscreen mode
- fullscreenEnabled()[source]
Returns a Boolean value indicating whether the document can be viewed in fullscreen mode
- getElementById(_id)[source]
[Returns the element that has the ID attribute with the specified value]
- getElementsByName(name: str)[source]
[Returns a NodeList containing all elements with a specified name]
- property head: HTMLHeadElement
Returns the <head> element of the document
- property images
Returns a collection of all <img> elements in the document
- property implementation
Returns the DOMImplementation object that handles this document
- importNode(node, deep=False)[source]
Imports a node from another document to this document.
- property links
Returns a collection of all <a> and <area> elements in the document that have a href attribute
- normalizeDocument()[source]
Removes empty Text nodes, and joins adjacent nodes
- open(index='index.html')[source]
Opens an HTML output stream to collect output from document.write()
- property pictureInPictureEnabled
Returns whether Picture-in-Picture mode is enabled.
- renameNode(node, namespaceURI: str, nodename: str)[source]
[Renames the specified node, and returns the renamed node.]
- property scripts
[Returns a collection of <script> elements in the document]
- Returns
[a collection of <script> elements in the document]
- Return type
[type]
- strictErrorChecking()[source]
Returns a Boolean value indicating whether to stop on the first error
- property title: str
[gets the title of the document]
- Returns
The title of the document
- Return type
[str]
- property visibilityState
Returns the visibility state of the document
- write(html: str = '')[source]
[writes HTML text to a document
- Parameters
html (str, optional) – [the content to write to the document]
- writeln(html: str = '')[source]
[writes HTML text to a document, followed by a line break]
- Parameters
html (str, optional) – [the content to write to the document]
- property xmlversion
Returns the version of XML used for the document
- class domonic.dom.DocumentFragment(*args)[source]
- property attributes: NamedNodeMap
Returns a NamedNodeMap of an element’s attributes
- getElementById(_id)
[Returns the element that has the ID attribute with the specified value]
- getElementsByTagName(tagName: str) HTMLCollection
[Returns a collection of all child elements with the specified tag name
- querySelector(query: str)
[Returns the first child element that matches a specified CSS selector(s) of an element]
- querySelectorAll(query: str)
[Returns all child elements that matches a specified CSS selector(s) of an element]
- class domonic.dom.DocumentType(name: str = 'html', publicId: str = '', systemId: str = '')[source]
- internalSubset()[source]
A DOMString of the internal subset, or None. Eg “<!ELEMENT foo (bar)>”.
- notations() NamedNodeMap [source]
A NamedNodeMap with notations declared in the DTD.
- class domonic.dom.Element(*args, **kwargs)[source]
Baseclass for all html tags
- append(*args)[source]
Inserts a set of Node objects or DOMString objects after the last child of the Element.
- property attributes: NamedNodeMap
Returns a NamedNodeMap of an element’s attributes
- blur()[source]
Removes focus from an element
- property classList
Returns the value of the classList attribute of an element
- property className
Sets or returns the value of the className attribute of an element
- click()[source]
Simulates a mouse-click on an element
- property clientHeight
Returns the height of an element, including padding
- property clientLeft
Returns the width of the left border of an element
- property clientTop
Returns the width of the top border of an element
- property clientWidth
Returns the width of an element, including padding
- property contentEditable: bool
Sets or returns whether an element is editable
- property dataset
Returns the value of the dataset attribute of an element
- property dir
returns the value of the dir attribute of an element
- exitFullscreen()[source]
Cancels an element in fullscreen mode
- firstElementChild()[source]
Returns the first child element of an element
- focus()[source]
Sets focus on an element
- getAttributeNS(namespaceURI, localName)[source]
Returns the value of the specified attribute
- getAttributeNodeNS(attr)[source]
Sets the attribute node of an element
- getBoundingClientRect()[source]
Returns the size of an element and its position relative to the viewport
- getElementsByClassName(className: str) HTMLCollection [source]
[Returns a collection of all child elements with the specified class name]
- getElementsBySelector(all_selectors, document)[source]
Get DOM elements based on the given CSS Selector https://simonwillison.net/2003/Mar/25/getElementsBySelector/ < original author http://www.openjs.com/scripts/dom/css_selector/ < ported to support ‘,’ https://bin-co.com/python/scripts/getelementsbyselector-html-css-query.php < ported to py2 (broken/bugs) BSD LICENSED
note - always needs a tag in the query i.e. (‘a.classname’) will work. but just (‘.classname’) wont
fixed and ported to py3 here. quite cool means other peoples code works on my dom # TODO - needs to work in conjuctions with _matchElement so querySelector works a bit better and dQuery picks it up # TOOD - *= node content
- getElementsByTagName(tagName: str) HTMLCollection [source]
[Returns a collection of all child elements with the specified tag name
- hasAttribute(attribute: str) bool [source]
Returns True if an element has the specified attribute, otherwise False
- property id
Sets or returns the value of the id attribute of an element
- property innerHTML
Sets or returns the content of an element
- insertAdjacentElement(position: str, element)[source]
Inserts an element adjacent to the current element
- insertAdjacentHTML(position: str, html: str)[source]
Inserts raw HTML adjacent to the current element
- isContentEditable() bool [source]
Returns true if the content of an element is editable, otherwise false
- lastElementChild()[source]
[Returns the last child element of an element]
- Returns
[the last child element of an element]
- Return type
[type]
- matches(s: str) bool [source]
[checks to see if the Element would be selected by the provided selectorString]
https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
- namespaceURI()[source]
Returns the namespace URI of an element
- property nextElementSibling
Returns the next element at the same node tree level
- property nextSibling
Returns the next node at the same node tree level
- normalize()[source]
Joins adjacent text nodes and removes empty text nodes in an element
- offsetHeight()[source]
Returns the height of an element, including padding, border and scrollbar
- offsetLeft()[source]
Returns the horizontal offset position of an element
- offsetParent()[source]
Returns the offset container of an element
- offsetTop()[source]
Returns the vertical offset position of an element
- offsetWidth()[source]
Returns the width of an element, including padding, border and scrollbar
- property parentElement
Returns the parent element node of an element
- prepend(*args)[source]
Prepends a node to the current element
- property previousElementSibling
returns the Element immediately prior to the specified one in its parent’s children list, or None if the specified element is the first one in the list.
- querySelector(query: str)[source]
[Returns the first child element that matches a specified CSS selector(s) of an element]
- querySelectorAll(query: str)[source]
[Returns all child elements that matches a specified CSS selector(s) of an element]
- remove()[source]
Removes the element from the DOM
- removeAttributeNS(namespaceURI, localName)[source]
Removes an attribute from an element
- removeAttributeNode(attribute)[source]
Removes a specified attribute node, and returns the removed node
- requestFullscreen()[source]
Shows an element in fullscreen mode
- scrollHeight()[source]
Returns the entire height of an element, including padding
- scrollIntoView()[source]
Scrolls the specified element into the visible area of the browser window
- scrollLeft()[source]
Sets or returns the number of pixels an element’s content is scrolled horizontally
- scrollTop()[source]
Sets or returns the number of pixels an element’s content is scrolled vertically
- scrollWidth()[source]
Returns the entire width of an element, including padding
- setAttribute(attribute, value)[source]
Sets or changes the specified attribute, to the specified value
- setAttributeNS(namespaceURI, localName, value)[source]
Sets an attribute in the given namespace
- setAttributeNode(attr)[source]
[Sets or changes the specified attribute node]
- Parameters
attr ([type]) – [an Attr object]
- setAttributeNodeNS(attr)[source]
Sets the attribute node of an element
- property style
returns the value of the style attribute of an element
- property title
returns the value of the title attribute of an element
- class domonic.dom.Entity(*args)[source]
- class domonic.dom.EntityReference(*args)[source]
The EntityReference interface represents a reference to an entity, either parsed or unparsed, in an Entity Node. Note that this is not a CharacterData node, and does not have any child nodes.
- class domonic.dom.HTMLAnchorElement(*args, **kwargs)[source]
- class domonic.dom.HTMLAreaElement(*args, **kwargs)[source]
- class domonic.dom.HTMLAudioElement(*args, autoplay: Optional[bool] = None, controls=None, loop=None, muted=None, preload=None, src=None, **kwargs)[source]
- class domonic.dom.HTMLBRElement(*args, **kwargs)[source]
- class domonic.dom.HTMLBaseElement(*args, href=None, target=None, **kwargs)[source]
- class domonic.dom.HTMLBaseFontElement(*args, **kwargs)[source]
- class domonic.dom.HTMLBodyElement(*args, aLink=None, background=None, bgColor=None, link=None, onload=None, onunload=None, text=None, vLink=None, **kwargs)[source]
- class domonic.dom.HTMLButtonElement(*args, disabled: Optional[bool] = None, form=None, formaction: Optional[str] = None, formenctype=None, formmethod=None, formnovalidate=None, formtarget=None, name=None, type=None, value=None, **kwargs)[source]
- class domonic.dom.HTMLCanvasElement(*args, width: Optional[int] = None, height: Optional[int] = None, **kwargs)[source]
- class domonic.dom.HTMLCollection(iterable=(), /)[source]
- class domonic.dom.HTMLContentElement(*args, **kwargs)[source]
- class domonic.dom.HTMLDListElement(*args, **kwargs)[source]
- class domonic.dom.HTMLDataElement(*args, **kwargs)[source]
- class domonic.dom.HTMLDataListElement(*args, **kwargs)[source]
- class domonic.dom.HTMLDialogElement(*args, open=None, **kwargs)[source]
- class domonic.dom.HTMLDivElement(*args, **kwargs)[source]
- class domonic.dom.HTMLDocument(*args, **kwargs)[source]
- class domonic.dom.HTMLElement(*args, **kwargs)[source]
- class domonic.dom.HTMLEmbedElement(*args, **kwargs)[source]
- class domonic.dom.HTMLFieldSetElement(*args, **kwargs)[source]
- class domonic.dom.HTMLFormControlsCollection(*args, **kwargs)[source]
- class domonic.dom.HTMLFormElement(*args, action: Optional[str] = None, autocomplete=None, enctype: Optional[str] = None, method: Optional[str] = None, name: Optional[str] = None, novalidate: Optional[bool] = None, target=None, **kwargs)[source]
- class domonic.dom.HTMLFrameSetElement(*args, **kwargs)[source]
- class domonic.dom.HTMLHRElement(*args, **kwargs)[source]
- class domonic.dom.HTMLHeadElement(*args, **kwargs)[source]
- class domonic.dom.HTMLHeadingElement(*args, **kwargs)[source]
- class domonic.dom.HTMLIFrameElement(*args, src=None, name=None, sandbox=None, allowfullscreen=None, **kwargs)[source]
- class domonic.dom.HTMLImageElement(*args, alt=None, src=None, crossorigin=None, height=None, ismap=None, longdesc=None, sizes=None, srcset=None, usemap=None, width=None, **kwargs)[source]
- class domonic.dom.HTMLInputElement(*args, accept=None, alt=None, autocomplete=None, autofocus=None, checked=None, dirname=None, disabled=None, form=None, formaction=None, formenctype=None, formmethod=None, formnovalidate=None, formtarget=None, height=None, _list=None, _max=None, maxlength=None, _min=None, multiple=None, name=None, pattern=None, placeholder=None, readonly=None, required=None, size=None, src=None, step=None, type=None, value=None, width=None, **kwargs)[source]
- class domonic.dom.HTMLIsIndexElement(*args, **kwargs)[source]
- class domonic.dom.HTMLKeygenElement(*args, **kwargs)[source]
- class domonic.dom.HTMLLIElement(*args, **kwargs)[source]
- class domonic.dom.HTMLLabelElement(*args, **kwargs)[source]
- class domonic.dom.HTMLLegendElement(*args, **kwargs)[source]
- class domonic.dom.HTMLLinkElement(*args, **kwargs)[source]
- class domonic.dom.HTMLMapElement(*args, **kwargs)[source]
- class domonic.dom.HTMLMediaElement(*args, **kwargs)[source]
- class domonic.dom.HTMLMetaElement(*args, charset=None, content=None, http_equiv=None, name=None, **kwargs)[source]
- class domonic.dom.HTMLMeterElement(*args, value=None, _min=None, _max=None, low=None, high=None, optimum=None, **kwargs)[source]
- class domonic.dom.HTMLModElement(*args, **kwargs)[source]
- class domonic.dom.HTMLOListElement(*args, **kwargs)[source]
- class domonic.dom.HTMLObjectElement(*args, **kwargs)[source]
- class domonic.dom.HTMLOptGroupElement(*args, **kwargs)[source]
- class domonic.dom.HTMLOptionElement(*args, disabled=None, label=None, selected=None, value=None, **kwargs)[source]
- class domonic.dom.HTMLOutputElement(*args, **kwargs)[source]
- class domonic.dom.HTMLParagraphElement(*args, **kwargs)[source]
- class domonic.dom.HTMLParamElement(*args, **kwargs)[source]
- class domonic.dom.HTMLPictureElement(*args, **kwargs)[source]
- class domonic.dom.HTMLPortalElement(*args, **kwargs)[source]
- class domonic.dom.HTMLPreElement(*args, **kwargs)[source]
- class domonic.dom.HTMLProgressElement(*args, **kwargs)[source]
- class domonic.dom.HTMLQuoteElement(*args, **kwargs)[source]
- class domonic.dom.HTMLScriptElement(*args, **kwargs)[source]
- class domonic.dom.HTMLSelectElement(*args, autofocus: Optional[bool] = None, disabled: Optional[bool] = None, multiple: Optional[bool] = None, name: Optional[str] = None, required: Optional[bool] = None, size: Optional[int] = None, **kwargs)[source]
- class domonic.dom.HTMLShadowElement(*args, **kwargs)[source]
- class domonic.dom.HTMLSourceElement(*args, **kwargs)[source]
- class domonic.dom.HTMLSpanElement(*args, **kwargs)[source]
- class domonic.dom.HTMLStyleElement(*args, **kwargs)[source]
- class domonic.dom.HTMLTableCaptionElement(*args, **kwargs)[source]
- class domonic.dom.HTMLTableCellElement(*args, **kwargs)[source]
- class domonic.dom.HTMLTableColElement(*args, **kwargs)[source]
- class domonic.dom.HTMLTableDataCellElement(*args, **kwargs)[source]
- class domonic.dom.HTMLTableElement(*args, align: Optional[str] = None, bgcolor=None, border=None, cellpadding=None, cellspacing=None, frame=None, rules=None, summary=None, width=None, **kwargs)[source]
- class domonic.dom.HTMLTableHeaderCellElement(*args, **kwargs)[source]
- class domonic.dom.HTMLTableRowElement(*args, **kwargs)[source]
- class domonic.dom.HTMLTableSectionElement(*args, **kwargs)[source]
- class domonic.dom.HTMLTemplateElement(*args, **kwargs)[source]
- class domonic.dom.HTMLTextAreaElement(*args, autofocus=None, cols=None, disabled=None, form=None, maxlength=None, name=None, placeholder=None, readonly=None, required=None, rows=None, wrap=None, **kwargs)[source]
- class domonic.dom.HTMLTimeElement(*args, **kwargs)[source]
- class domonic.dom.HTMLTitleElement(*args, **kwargs)[source]
- class domonic.dom.HTMLTrackElement(*args, **kwargs)[source]
- class domonic.dom.HTMLUListElement(*args, **kwargs)[source]
- class domonic.dom.HTMLUnknownElement(*args, **kwargs)[source]
- class domonic.dom.HTMLVideoElement(*args, autoplay=None, controls=None, height=None, loop=None, muted=None, poster=None, preload=None, src=None, width=None, **kwargs)[source]
- class domonic.dom.Node(*args, **kwargs)[source]
An abstract base class upon which many other DOM API objects are based
- appendChild(aChild: Node) Node [source]
Adds a child to the current element. If item is a DocumentFragment, all its children are added.
- Parameters
item (Node) – The Node to add.
- property attrib
Returns the attributes of the current node as a dict not a NamedNodeMap
- property childElementCount: int
Returns the number of child elements an element has
- property childNodes: NodeList
Returns a live NodeList containing all the children of this node
- property children
Returns a collection of an element’s child element (excluding text and comment nodes)
- compareDocumentPosition(otherElement) int [source]
An integer value representing otherNode’s position relative to node as a bitmask combining the following constant properties of Node:
https://stackoverflow.com/questions/8334286/cross-browser-compare-document-position
- contains(node)[source]
Check whether a node is a descendant of a given node
- property firstChild
Returns the first child node of an element
- insertBefore(new_node, reference_node=None)[source]
inserts a node before a reference node as a child of a specified parent node. this will remove the node from its previous parent node, if any.
# TODO - can throw value error if wrong ordered params. may be helpful to catch to say so.
- isDefaultNamespace(ns)[source]
Checks if a namespace is the default namespace
- isEqualNode(node)[source]
Checks if two elements are equal
- isSameNode(node)[source]
Checks if two elements are the same node
- iter(tag=None)[source]
Creates a tree iterator with the current element as the root. The iterator iterates over this element and all elements below it, in document (depth first) order. If tag is not None or ‘*’, only elements whose tag equals tag are returned from the iterator. If the tree structure is modified during iteration, the result is undefined.
- property lastChild
Returns the last child node of an element
- lookupNamespaceURI(ns: str)[source]
Returns the namespace URI for a given prefix
- Parameters
ns – prefix - i.e ‘xml’, ‘xlink’, ‘svg’, etc
- lookupPrefix(ns)[source]
Returns the prefix for a given namespace URI
- property nextSibling
[returns the next sibling of the current node.]
- property nodeName
Returns the name of a node
- property nodeValue
Sets or returns the value of a node
- normalize()[source]
Normalize a node’s value
- property ownerDocument
Returns the root element (document object) for an element
- property previousSibling
[returns the previous sibling of the current node.]
- removeChild(node)[source]
removes a child node from the DOM and returns the removed node.
- replaceChild(newChild, oldChild)[source]
[Replaces a child node within the given (parent) node.]
- property rootNode
[read-only property returns a Node object representing the topmost node in the tree, or the current node if it’s the topmost node in the tree]
- Returns
[the topmost Node in the tree]
- Return type
[Node]
- property tag
Returns the tag name of the current node
- property tail
Returns the text content of the current node
- property text
Returns the text content of the current node
- property textContent
Returns the text content of a node and its descendants
- class domonic.dom.NodeIterator(root, whatToShow=4294967295, filter=None, entityReferenceExpansion=False)[source]
[NodeIterator is an iterator object that iterates over the descendants of a node, in tree order.]
- nextNode()[source]
Returns the next Node in the document, or null if there are none.
- pointerBeforeReferenceNode() bool [source]
Returns a boolean flag that indicates whether the NodeIterator is anchored before, the flag being true, or after, the flag being false, the anchor node.
- previousNode()[source]
Returns the previous Node in the document, or null if there are none.
- class domonic.dom.NodeList(iterable=(), /)[source]
NodeList objects are collections of nodes
- entries() Iterable[Tuple[int, Node]] [source]
Returns an iterator, allowing code to go through all key/value pairs contained in the collection. (In this case, the keys are numbers starting from 0 and the values are nodes.
- item(index) Node [source]
Returns an item in the list by its index, or null if the index is out-of-bounds.
- class domonic.dom.ParentNode(*args, **kwargs)[source]
not tested yet
- property children: NodeList
Return list of child nodes.
- property firstElementChild
First Element child node.
- property lastElementChild
Last Element child node.
- class domonic.dom.ProcessingInstruction(target, data)[source]
- class domonic.dom.RadioNodeList(name: str)[source]
- property value
Returns the value of the first element in the collection, or null if there are no elements in the collection.
- class domonic.dom.ShadowRoot(host, mode='open')[source]
property on element that has hidden DOM
- caretPositionFromPoint()[source]
Returns a CaretPosition object containing the DOM node containing the caret, and caret’s character offset within that node.
- elementFromPoint(x, y)[source]
Returns the topmost element at the specified coordinates.
- elementsFromPoint(x, y)[source]
Returns an array of all elements at the specified coordinates.
- getSelection()[source]
Returns a Selection object representing the range of text selected by the user, or the current position of the caret.
- class domonic.dom.Text(*args, **kwargs)[source]
Text Node
- property assignedSlot
Returns the slot whose assignedNodes contains this node.
- property childNodes
Returns a live NodeList containing all the children of this node
- property firstChild
Returns the first child node of an element
- property nodeName
Returns the name of a node
- splitText(offset: int)[source]
Splits the Text node into two Text nodes at the specified offset, keeping both in the tree as siblings. The first node is returned, while the second node is discarded and exists outside the tree.
- property wholeText
Returns a DOMString containing all the text content of the node and its descendants.
- class domonic.dom.TreeWalker(node, whatToShow=4294967295, _filter=None, expandEntityReferences=False)[source]
The TreeWalker object represents the nodes of a document subtree and a position within them.
- firstChild()[source]
Moves the current Node to the first visible child of the current node, and returns the found child. It also moves the current node to this child. If no such child exists, returns null and the current node is not changed.
- lastChild()[source]
Moves the current Node to the last visible child of the current node, and returns the found child. It also moves the current node to this child. If no such child exists, null is returned and the current node is not changed.
- nextNode()[source]
Moves the current Node to the next visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, returns None and the current node is not changed. can be used in a while loop to iterate over all the nodes in the document order.
- nextSibling()[source]
Moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
- parentNode()[source]
Moves the current Node to the first visible ancestor node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
- previousNode()[source]
Moves the current Node to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
- previousSibling()[source]
Moves the current Node to its previous sibling, if any, and returns the found sibling. If there is no such node, return null and the current node is not changed.
- property root
Returns a Node representing the root node as specified when the TreeWalker was created.
- tree
Is a boolean value indicating, when discarding an entity reference its whole sub-tree must be discarded at the same time.
- whatToShow(options)[source]
Returns an unsigned long being a bitmask made of constants describing the types of Node that must be presented. Non-matching nodes are skipped, but their children may be included, if relevant. The possible values are:
- domonic.dom.console
# self.screen = type(‘screen’, (DOM,), {‘name’:’screen’})
domonic.events¶
https://developer.mozilla.org/en-US/docs/Web/Events
- class domonic.events.AnimationEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- ANIMATIONEND: str = 'animationend'
- ANIMATIONITERATION: str = 'animationiteration'
- ANIMATIONSTART: str = 'animationstart'
- animationName
Returns the name of the animation
- elapsedTime
Returns the number of seconds an animation has been running
- pseudoElement
Returns the name of the pseudo-element of the animation
- class domonic.events.BeforeUnloadEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- BEFOREUNLOAD: str = 'beforeunload'
BeforeUnloadEvent
- class domonic.events.ClipboardEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- COPY: str = 'copy'
- CUT: str = 'cut'
- PASTE: str = 'paste'
- clipboardData
Returns an object containing the data affected by the clipboard operation
- class domonic.events.CompositionEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- class domonic.events.CustomEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- class domonic.events.DOMContentLoadedEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- DOMCONTENTLOADED: str = 'DOMContentLoaded'
- document
Returns the document that was loaded
- class domonic.events.DragEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- DRAG: str = 'drag'
- DROP: str = 'drop'
- END: str = 'dragend'
- ENTER: str = 'dragenter'
- EXIT: str = 'dragexit'
- LEAVE: str = 'dragleave'
- OVER: str = 'dragover'
- START: str = 'dragstart'
- dataTransfer
Returns the data that is dragged/dropped
- class domonic.events.ErrorEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- ERROR: str = 'error'
- class domonic.events.Event(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
event
- ABORT: str = 'abort'
- AFTERPRINT: str = 'afterprint'
- BEFOREPRINT: str = 'beforeprint'
- BEFOREUNLOAD: str = 'beforeunload'
- CANPLAY: str = 'canplay'
- CANPLAYTHROUGH: str = 'canplaythrough'
- CHANGE: str = 'change'
- DURATIONCHANGE: str = 'durationchange'
- EMPTIED: str = 'emptied'
- ENDED: str = 'ended'
- ERROR: str = 'error'
- FULLSCREENCHANGE: str = 'fullscreenchange'
- FULLSCREENERROR: str = 'fullscreenerror'
- INPUT: str = 'input'
- INVALID: str = 'invalid'
- LOAD: str = 'load'
- LOADEDDATA: str = 'loadeddata'
- LOADEDMETADATA: str = 'loadedmetadata'
- MESSAGE: str = 'message'
- OFFLINE: str = 'offline'
- ONLINE: str = 'online'
- OPEN: str = 'open'
- PAUSE: str = 'pause'
- PLAY: str = 'play'
- PLAYING: str = 'playing'
- PROGRESS: str = 'progress'
- RATECHANGE: str = 'ratechange'
- READYSTATECHANGE: str = 'readystatechange'
- RESET: str = 'reset'
- RESIZE: str = 'resize'
- SCROLL: str = 'scroll'
- SEARCH: str = 'search'
- SEEKED: str = 'seeked'
- SEEKING: str = 'seeking'
- SELECT: str = 'select'
- SHOW: str = 'show'
- STALLED: str = 'stalled'
- SUBMIT: str = 'submit'
- SUSPEND: str = 'suspend'
- TOGGLE: str = 'toggle'
- UNLOAD: str = 'unload'
- VOLUMECHANGE: str = 'volumechange'
- WAITING: str = 'waiting'
- stopPropagation()[source]
[prevents further propagation of the current event in the capturing and bubbling phases]
- domonic.events.EventDispatcher
legacy alias
- class domonic.events.EventTarget(*args, **kwargs)[source]
EventTarget is a class you can extend to give your obj event dispatching abilities
- class domonic.events.ExtendableEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- extendable
Returns whether the event is extendable or not
- timeStamp: float
Returns the time stamp of the event
- class domonic.events.FetchEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- FETCH: str = 'fetch'
- clientId
Returns the client ID of the fetch request
- property isReload
Returns whether the request is a reload or not
- request
Returns the request object
- respondWith(response)[source]
Returns a promise that resolves to the response object
- waitUntil(promise)[source]
Returns a promise that resolves when the response is available
- class domonic.events.FocusEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- BLUR: str = 'blur'
- FOCUS: str = 'focus'
- FOCUSIN: str = 'focusin'
- FOCUSOUT: str = 'focusout'
- class domonic.events.GamePadEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- START: str = 'gamepadconnected'
- STOP: str = 'gamepaddisconnected'
- class domonic.events.HashChangeEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- CHANGE: str = 'hashchange'
- class domonic.events.InputEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- CHANGE: str = 'change'
- INPUT: str = 'input'
- SELECT: str = 'select'
- data
Returns the inserted characters
- dataTransfer
Returns an object containing information about the inserted/deleted data
- getTargetRanges()[source]
Returns an array containing target ranges that will be affected by the insertion/deletion
- inputType
Returns the type of the change (i.e “inserting” or “deleting”)
- isComposing
Returns whether the state of the event is composing or not
- class domonic.events.KeyboardEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
keyboard events
- DOM_KEY_LOCATION_JOYSTICK: int = 5
- DOM_KEY_LOCATION_LEFT: int = 0
- DOM_KEY_LOCATION_MOBILE: int = 4
- DOM_KEY_LOCATION_NUMPAD: int = 3
- DOM_KEY_LOCATION_RIGHT: int = 2
- DOM_KEY_LOCATION_STANDARD: int = 1
- KEYDOWN: str = 'keydown'
- KEYPRESS: str = 'keypress'
- KEYUP: str = 'keyup'
- class domonic.events.MessageEvent(_type, options: Optional[dict] = None, *args, **kwargs)[source]
- CONNECT: str = 'connect'
- DISCONNECT: str = 'disconnect'
- MESSAGE: str = 'message'
- data
Returns the data of the message
- lastEventId
Returns the last event id of the message
- origin
Returns the origin of the message
- ports
Returns the ports of the message
- source
Returns the source of the message
- class domonic.events.MouseEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
mouse events
- CLICK: str = 'click'
- CONTEXTMENU: str = 'contextmenu'
- DBLCLICK: str = 'dblclick'
- MOUSEDOWN: str = 'mousedown'
- MOUSEENTER: str = 'mouseenter'
- MOUSELEAVE: str = 'mouseleave'
- MOUSEMOVE: str = 'mousemove'
- MOUSEOUT: str = 'mouseout'
- MOUSEOVER: str = 'mouseover'
- MOUSEUP: str = 'mouseup'
- getModifierState()[source]
Returns an array containing target ranges that will be affected by the insertion/deletion
- class domonic.events.PageTransitionEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- PAGEHIDE: str = 'pagehide'
- PAGESHOW: str = 'pageshow'
- persisted
Returns whether the webpage was cached by the browser
- class domonic.events.PointerEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- POINTER: str = 'pointer'
- POINTERCANCEL: str = 'pointercancel'
- POINTERDOWN: str = 'pointerdown'
- POINTERENTER: str = 'pointerenter'
- POINTERLEAVE: str = 'pointerleave'
- POINTERMOVE: str = 'pointermove'
- POINTEROUT: str = 'pointerout'
- POINTEROVER: str = 'pointerover'
- POINTERUP: str = 'pointerup'
- class domonic.events.PopStateEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- POPSTATE: str = 'popstate'
- state
Returns an object containing a copy of the history entries
- class domonic.events.ProgressEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- ABORT: str = 'abort'
- ERROR: str = 'error'
- LOAD: str = 'load'
- LOADED: str = 'loaded'
- LOADEND: str = 'loadend'
- LOADSTART: str = 'loadstart'
- PROGRESS: str = 'progress'
- TIMEOUT: str = 'timeout'
- class domonic.events.PromiseRejectionEvent(_type, options=None, *args, **kwargs)[source]
- HANDLED: str = 'rejectionhandled'
- UNHANDLED: str = 'unhandledrejection'
- isRejected
Returns whether the promise was rejected or not
- promise
Returns the promise that was rejected
- reason
Returns the reason of the rejection
- class domonic.events.SVGEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- ABORT: str = 'abort'
- ERROR: str = 'error'
- LOAD: str = 'load'
- LOADEDDATA: str = 'loadeddata'
- LOADEDMETADATA: str = 'loadedmetadata'
- LOADSTART: str = 'loadstart'
- PROGRESS: str = 'progress'
- SCROLL: str = 'scroll'
- UNLOAD: str = 'unload'
- class domonic.events.SecurityPolicyViolationEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- SECURITY_POLICY_VIOLATION: str = 'securitypolicyviolation'
- blockedURI
Returns the blocked URI
- frame
Returns the frame that violated the policy
- isFrameAncestor
Returns whether the frame is an ancestor of the frame that violated the policy
- isMainFrame
Returns whether the frame is the main frame
- originalPolicy
Returns the original policy
- timeStamp: float
Returns the time stamp of the event
- violatedDirective
Returns the violated directive
- class domonic.events.StorageEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- STORAGE: str = 'storage'
- key
Returns the key of the changed storage item
- newValue
Returns the new value of the changed storage item
- oldValue
Returns the old value of the changed storage item
- storageArea
Returns an object representing the affected storage object
- url
Returns the URL of the changed item’s document
- class domonic.events.SubmitEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- SUBMIT: str = 'submit'
- class domonic.events.SyncEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- SYNC: str = 'sync'
- lastChance
Returns whether the sync event is the last chance or not
- tag
Returns the tag of the sync event
- timeStamp: float
Returns the time stamp of the event
- class domonic.events.TimerEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- TIMER: str = 'timer'
- TIMER_COMPLETE: str = 'timercomplete'
TimerEvent
- class domonic.events.TouchEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- TOUCHCANCEL: str = 'touchcancel'
- TOUCHEND: str = 'touchend'
- TOUCHMOVE: str = 'touchmove'
- TOUCHSTART: str = 'touchstart'
- class domonic.events.TransitionEvent(_type: str, options: Optional[dict] = None, *args, **kwargs)[source]
- TRANSITIONEND: str = 'transitionend'
- elapsedTime
Returns the number of seconds a transition has been running
- propertyName
Returns the name of the transition
- pseudoElement
Returns the name of the pseudo-element of the transition
- class domonic.events.TweenEvent(_type, source=None, bubbles=False, cancelable=False)[source]
- COMPLETE: str = 'onComplete'
- PAUSE: str = 'onPause'
- RESET: str = 'onReset'
- START: str = 'onStart'
- STOP: str = 'onStop'
- TIMER: str = 'onTimer'
- UNPAUSE: str = 'onUnPause'
- UPDATE_END: str = 'onUpdateEnd'
- UPDATE_START: str = 'onUpdateStart'