Element#

class toui.elements.Element(tag_name='div')[source]#

Bases: object

Creates an HTML element.

Examples

Creating a <button> HTML element:

>>> button = Element("button")
>>> button
<button></button>

Setting the inner HTML content of the element:

>>> button.set_content("Click me")
>>> button
<button>Click me</button>

Setting the element’s attributes:

>>> button.set_attr("name", "button-name")
>>> button
<button name="button-name">Click me</button>

Methods#

toui.elements.Element.add_content

Adds to the inner HTML content of the element.

toui.elements.Element.add_to_class_list

Adds the specified class to the HTML element if it does not exist.

toui.elements.Element.del_attr

Removes an HTML element attribute.

toui.elements.Element.from_bs4_tag

Converts a bs4.element.Tag object to an Element object.

toui.elements.Element.from_str

Converts HTML code to an Element object.

toui.elements.Element.get_attr

Gets the value of an HTML element attribute.

toui.elements.Element.get_class_list

Gets all classes of the HTML element as a list.

toui.elements.Element.get_content

Gets the inner HTML content of the element.

toui.elements.Element.get_element

Gets a child element from its id attribute.

toui.elements.Element.get_elements

Get children elements by their tag name and attributes.

toui.elements.Element.get_files

Gets uploaded files from element.

toui.elements.Element.get_height_property

Gets the value of the CSS property height inside the style attribute.

toui.elements.Element.get_id

Gets the id attribute of the HTML element.

toui.elements.Element.get_parent

Gets the parent element.

toui.elements.Element.get_selected

Gets the selected option of the HTML element <select>.

toui.elements.Element.get_selector

Gets the CSS selector of an element.

toui.elements.Element.get_style_property

Gets the value of a CSS property inside the style attribute.

toui.elements.Element.get_unique_selector

Gets the unique CSS selector of an element.

toui.elements.Element.get_value

Gets the value attribute of the HTML element.

toui.elements.Element.get_width_property

Gets the value of the CSS property width inside the style attribute.

toui.elements.Element.has_attr

Checks if the HTML element has the specified attribute.

toui.elements.Element.on

Creates an HTML event attribute and adds a Python function to it.

toui.elements.Element.onclick

Creates the HTML event attribute onclick and adds a Python function to it.

toui.elements.Element.remove_from_class_list

Removes all occurences of the specified class from the HTML element.

toui.elements.Element.set_attr

Sets the value of an HTML element attribute.

toui.elements.Element.set_content

Sets the inner HTML content of the element.

toui.elements.Element.set_height_property

Sets the value of the CSS property height inside the style attribute.

toui.elements.Element.set_id

Sets the value of the id attribute.

toui.elements.Element.set_style_property

Sets the value of a CSS property inside the style attribute.

toui.elements.Element.set_value

Sets the value of the value attribute.

toui.elements.Element.set_width_property

Sets the value of the CSS property width inside the style attribute.

toui.elements.Element.to_bs4_tag

Converts the Element object to a bs4.element.Tag object.

toui.elements.Element.to_str

Converts the Element object to HTML code.