HTML Tag Class

wdom.dom.Tag class provides DOM implementation synchronized both on python and browser.

Tag class

Web-connected HTML tag classes.

class wdom.tag.Tag(*args, attrs=None, **kwargs)[source]

Bases: wdom.web_node.WdomElement

Base class for html tags.

HTMLElement requires to specify tag name when instanciate it, but this class and sublasses have default tag name and not need to specify it for each thier instances.

tag = 'tag'

Tag name used for this node.

type_ = ''

use for <input> tag’s type

is_ = ''

custom element which extends built-in tag (like <table is=”your-tag”>)

addClass(*classes)

[Not Standard] Add classes to this node.

Return type:None
after(*nodes)

Append nodes after this node.

If nodes contains str, it will be converted to Text node.

Return type:None
append(*nodes)

Append new nodes after last child node.

Return type:None
appendChild(child)

Append child node at the last of child nodes.

If this instance is connected to the node on browser, the child node is also added to it.

Return type:Node
before(*nodes)

Insert nodes before this node.

If nodes contains str, it will be converted to Text node.

Return type:None
childNodes

Return child nodes of this node.

Returned object is an instance of NodeList, which is a list like object but not support any modification. NodeList is a live object, which means that changes on this node is reflected to the object.

Return type:NodeList[]
children

Return list of child nodes.

Currently this is not a live object.

Return type:NodeList[]
className

Get/Set class name as/by string.

Return type:str
click()

Send click event.

Return type:None
cloneNode(deep=False)

Return new copy of this node.

If optional argument deep is specified and is True, new node has clones of child nodes of this node (if presents).

Return type:AbstractNode
connected

When this instance has any connection, return True.

Return type:bool
dispatchEvent(event)

Emit events.

Return type:None
draggable

Get draggable property.

Return type:Union[bool, str]
empty()

Remove all child nodes from this node.

Return type:None
end_tag

Retrun html end tag.

If tag is empty tag like <img> or <br>, return empty string.

Return type:str
exec(script)

Execute JavaScript on the related browser node.

Return type:None
firstChild

Return the first child node.

If this node does not have any child, return None.

Return type:Optional[AbstractNode]
firstElementChild

First Element child node.

If this node has no element child, return None.

Return type:Optional[AbstractNode]
getAttributeNode(attr)

Get attribute of this node as Attr format.

If this node does not have attr, return None.

Return type:Optional[Attr]
getBoundingClientRect()

Get size of this node on browser.

Return type:None
getElementsBy(cond)

Return list of child elements of start_node which matches cond.

cond must be a function which gets a single argument Element, and returns boolean. If the node matches requested condition, cond should return True. This searches all child elements recursively.

Parameters:
  • start_node (ParentNode) –
  • cond – Callable[[Element], bool]
Return type:

NodeList[Element]

getElementsByClassName(class_name)

Get child nodes which has class_name class attribute.

Return type:NodeList[]
getElementsByTagName(tag)

Get child nodes which tag name is tag.

Return type:NodeList[]
get_class_list()

Get class-level class list, including all super class’s.

Return type:DOMTokenList[]
hasAttribute(attr)

Return True if this node has attr.

Return type:bool
hasAttributes()

Return True if this node has any attributes.

Return type:bool
hasChildNodes()

Return True if this node has child nodes, otherwise return False.

Return type:bool
hasClass(class_)

[Not Standard] Return if this node has class_ class or not.

Return type:bool
hasClasses()

[Not Standard] Return if this node has any classes or not.

Return type:bool
hidden

Getter: Return True if this element has hidden attribute. Otherwise return False. Setter: If True, add hidden attribute to this element. Otherwise remove hidden. Deleter: Remove hidden attribute from this element.

Return type:bool
hide()

[Not Standard] Hide this node on browser.

Return type:None
html

Return HTML representation of this node.

Return type:str
html_noid

Get html representation of this node without rimo_id.

Return type:str
id

Getter: Get value of id attribute of this element, as string. If id is not defined, return empty string. Setter: Set the value of id attribute of this element. Deleter: Remove id attribute from this element.

Return type:str
index(node)

Return index of the node.

If the node is not a child of this node, raise ValueError.

Return type:int
innerHTML

Return HTML representation of child nodes.

Return type:str
insertAdjacentHTML(position, html)

Parse html to DOM and insert to position.

position is a case-insensive string, and must be one of “beforeBegin”, “afterBegin”, “beforeEnd”, or “afterEnd”.

Return type:None
insertBefore(child, ref_node)

Insert new child node before the reference child node.

If the reference node is not a child of this node, raise ValueError. If this instance is connected to the node on browser, the child node is also added to it.

Return type:Node
js_exec(method, *args)

Execute method in the related node on browser.

Other keyword arguments are passed to params attribute. If this node is not in any document tree (namely, this node does not have parent node), the method is not executed.

Return type:None
js_query(query)

Send query to related DOM on browser.

Parameters:query (str) – single string which indicates query type.
Return type:Awaitable[+T_co]
lastChild

Return the last child node.

If this node does not have any child, return None.

Return type:Optional[AbstractNode]
lastElementChild

Last Element child node.

If this node has no element child, return None.

Return type:Optional[AbstractNode]
length

Return number of child nodes.

Return type:int
localName

Return tag name (lower case).

Return type:str
nextElementSibling

Next Element Node.

If this node has no next element node, return None.

Return type:Optional[AbstractNode]
nextSibling

Return the next sibling of this node.

If there is no next sibling, return None.

Return type:Optional[AbstractNode]
nodeName

Return tag name (capital case).

Return type:str
on_event_pre(event)

Run before dispatching events.

Used for seting values changed by user input, in some elements like input, textarea, or select. In this method, event.currentTarget is a dict sent from browser.

Return type:None
on_response(msg)

Run when get response from browser.

Return type:None
outerHTML

Return html representation of this node.

Equivalent to self.html.

Return type:str
ownerDocument

Return the owner document of this node.

Owner document is an ancestor document node of this node. If this node (or node tree including this node) is not appended to any document node, this property returns None.

Return type:Document or None
parentNode

Return parent node.

If this node does not have a parent, return None.

Return type:Optional[AbstractNode]
prepend(*nodes)

Insert new nodes before first child node.

Return type:None
previousElementSibling

Previous Element Node.

If this node has no previous element node, return None.

Return type:Optional[AbstractNode]
previousSibling

Return the previous sibling of this node.

If there is no previous sibling, return None.

Return type:Optional[AbstractNode]
query(relativeSelectors)

Not Implemented.

Return type:AbstractNode
queryAll(relativeSelectors)

Not Implemented.

Return type:NodeList[]
querySelector(selectors)

Not Implemented.

Return type:AbstractNode
querySelectorAll(selectors)

Not Implemented.

Return type:NodeList[]
remove()

Remove this node from parent’s DOM tree.

Return type:None
removeAttribute(attr)

Remove attr from this node.

Return type:None
removeAttributeNode(attr)

Remove Attr node from this node.

Return type:Optional[Attr]
removeChild(child)

Remove the child node from this node.

If the node is not a child of this node, raise ValueError.

Return type:Node
removeClass(*classes)

[Not Standard] Remove classes from this node.

Return type:None
replaceChild(new_child, old_child)

Replace child nodes.

Return type:Node
replaceWith(*nodes)

Replace this node with nodes.

If nodes contains str, it will be converted to Text node.

Return type:None
rimo_id

Get rimo_id attribute.

This attribute is used to relate python node and browser DOM node.

Return type:str
setAttribute(attr, value)

Set attr and value in this node.

Return type:None
setAttributeNode(attr)

Set Attr node as this node’s attribute.

Return type:None
show()

[Not Standard] Show this node on browser.

Return type:None
start_tag

Return HTML start tag.

Return type:str
style

Return style attribute of this node.

Return type:CSSStyleDeclaration
tagName

Return tag name (capital case).

Return type:str
textContent

Return text contents of this node and all chid nodes.

When any value is set to this property, all child nodes are removed and new value is set as a text node.

Return type:str
title

Getter: Get value of title attribute of this element, as string. If title is not defined, return empty string. Setter: Set the value of title attribute of this element. Deleter: Remove title attribute from this element.

Return type:str
ws_send(obj)

Send obj as message to the related nodes on browser.

Parameters:obj (dict) – Message is serialized by JSON object and send via WebSocket connection.
Return type:None
wdom.tag.NewTagClass(class_name, tag=None, bases=(<class 'wdom.tag.Tag'>, ), **kwargs)[source]

Generate and return new Tag class.

If tag is empty, lower case of class_name is used for a tag name of the new class. bases should be a tuple of base classes. If it is empty, use Tag class for a base class. Other keyword arguments are used for class variables of the new class.

Example:

MyButton = NewTagClass('MyButton', 'button', (Button,),
                       class_='btn', is_='my-button')
my_button = MyButton('Click!')
print(my_button.html)

>>> <button class="btn" id="111111111" is="my-button">Click!</button>
Return type:type
class wdom.tag.RawHtmlNode(*args, **kwargs)[source]

Bases: wdom.tag.Tag

Does not escape inner contents, similar to <script> tag.

This node wraps contents by <div style="display: inline">...</div> and does not escape inner text. Similar to wdom.node.RawHtmlNode, but the difference is this class wraps text by div tag. This enables to treat multi-tag html string as if it’s single node.

Useful for showing generated HTML contents, like markdown conversion result, graph plots, or HTML formatted reports. Usually faster than Tag.innerHTML = html, since this node skips html parsing process to WdomElement.

Example:

doc.body.appnd(RawHtml('<h1>Title</h1>'))

Note

Inner html is not WdomElement, so you cant control them from python.

Add display: inline style on div tag.

List of HTML Tag Classes

class wdom.tag.A(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag, wdom.element.HTMLAnchorElement

class wdom.tag.Body(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Br(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Button(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag, wdom.element.HTMLButtonElement

class wdom.tag.Cite(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Code(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Dd(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Div(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Dl(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Dt(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Em(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Form(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag, wdom.element.HTMLFormElement

class wdom.tag.H1(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.H2(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.H3(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.H4(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.H5(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.H6(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Head(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Hr(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Html(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Img(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Input(*args, **kwargs)[source]

Bases: wdom.tag.Tag, wdom.element.HTMLInputElement

Base class for <input> element.

class wdom.tag.Label(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag, wdom.element.HTMLLabelElement

class wdom.tag.Li(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

Bases: wdom.tag.Tag

class wdom.tag.Meta(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Ol(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Option(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag, wdom.element.HTMLOptionElement

class wdom.tag.P(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Pre(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Script(*args, type='text/javascript', **kwargs)[source]

Bases: wdom.tag.Tag, wdom.element.HTMLScriptElement

Base class for <script> tag.

Inner contents of this node is not escaped.

class wdom.tag.Select(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag, wdom.element.HTMLSelectElement

class wdom.tag.Span(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Strong(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Style(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag, wdom.element.HTMLStyleElement

class wdom.tag.Table(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Tbody(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Td(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Textarea(*args, attrs=None, **kwargs)[source]

Bases: wdom.tag.Tag, wdom.element.HTMLTextAreaElement

Base class for <textarea> element.

class wdom.tag.Tfoot(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Th(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Thead(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Title(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Tr(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.U(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag

class wdom.tag.Ul(*args, attrs=None, **kwargs)

Bases: wdom.tag.Tag