Element
Overview
Element is a class in Aspose.Html FOSS for Python.
Inherits from: Node.
An HTML or XML element node.
This class provides 72 methods for working with Element objects in Python programs.
Available methods include: __init__, add_event_listener, after, append, append_child, attach_shadow, before, check_visibility, clone_node, closest, compare_document_position, contains, and 60 additional methods.
All public members are accessible to any Python application after installing the Aspose.Html FOSS for Python package.
Properties: assigned_slot, attributes, child_element_count, child_nodes, children, class_list, and 43 more.
Properties
| Name | Type | Access | Description |
|---|---|---|---|
node_name | str | Read | The qualified tag name (uppercase for HTML elements). |
tag_name | str | Read | The qualified tag name in uppercase (HTML elements). |
local_name | str | Read | The local part of the qualified name (lowercase). |
namespace_uri | str | None | Read | The namespace URI, or None for no namespace. |
style_sheets | "StyleSheetList" | Read | Live stylesheet list applicable to this element’s document. |
prefix | str | None | Read | The namespace prefix, or None. |
id | str | Read | The value of the id attribute, or '' if not present. |
class_name | str | Read | The value of the class attribute, or ''. |
class_list | "DOMTokenList" | Read | Live mutable set of CSS class tokens backed by the class attribute. |
dataset | "DOMStringMap" | Read | Live dict-like view of the element’s data-* custom attributes. |
attributes | NamedNodeMap | Read | The ordered map of Attr objects for this element. |
children | HTMLCollection | Read | A live HTMLCollection of Element-type children only. |
first_element_child | Element | None | Read | The first Element child, or None. |
last_element_child | Element | None | Read | The last Element child, or None. |
next_element_sibling | Element | None | Read | The next sibling that is an Element, or None. |
previous_element_sibling | Element | None | Read | The previous sibling that is an Element, or None. |
child_element_count | int | Read | The number of Element children. |
inner_html | str | Read/Write | The serialised HTML content of all children (innerHTML). |
outer_html | str | Read/Write | The serialised HTML of this element and all its descendants (outerHTML). |
text_content | str | None | Read/Write | The concatenation of all descendant Text node data (DFS order). |
style | "CSSStyleDeclaration" | Read | The inline style of this element as a live CSSStyleDeclaration. |
scroll_width | int | Read | Content scroll width in CSS pixels (stub: 0). |
scroll_height | int | Read | Content scroll height in CSS pixels (stub: 0). |
client_width | int | Read | Inner width including padding, excluding border (stub: 0). |
client_height | int | Read | Inner height including padding, excluding border (stub: 0). |
scroll_top | int | Read/Write | Vertical scroll offset in CSS pixels (stub: 0). |
scroll_left | int | Read/Write | Horizontal scroll offset in CSS pixels (stub: 0). |
offset_width | int | Read | Layout border-box width in CSS pixels (stub: 0). |
offset_height | int | Read | Layout border-box height in CSS pixels (stub: 0). |
offset_top | int | Read | Top offset from offsetParent in CSS pixels (stub: 0). |
offset_left | int | Read | Left offset from offsetParent in CSS pixels (stub: 0). |
offset_parent | None | Read | The offset parent element; always None in headless mode. |
client_top | int | Read | Width of the top CSS border in pixels; always 0 in headless mode. |
client_left | int | Read | Width of the left CSS border in pixels; always 0 in headless mode. |
part | "DOMTokenList" | Read | Live DOMTokenList reflecting the element part attribute. |
shadow_root | `` | Read | Always None in headless mode. |
slot | str | Read/Write | Reflects the slot content attribute (DOM §4.2.3). |
assigned_slot | `` | Read | Always None in headless mode. |
node_type | int | Read | Integer node type constant from NodeType. |
node_value | str | None | Read/Write | Character data for CharacterData nodes; None otherwise. |
parent_node | Node | None | Read | The parent node, or None if this node has no parent. |
parent_element | Element | None | Read | The parent node if it is an Element; None otherwise. |
is_connected | bool | Read | Whether this node is part of a document’s node tree (WHATWG DOM §4.4). |
owner_document | Document | None | Read | The Document this node belongs to, or None for Document itself. |
child_nodes | NodeList | Read | A live NodeList of all child nodes. |
first_child | Node | None | Read | The first child node, or None. |
last_child | Node | None | Read | The last child node, or None. |
previous_sibling | Node | None | Read | The preceding sibling node, or None. |
next_sibling | Node | None | Read | The following sibling node, or None. |
Methods
| Signature | Description |
|---|---|
__init__(local_name: str, namespace_uri: str | None, prefix: str | None, owner_document: Document | None) | Calls init(local_name, namespace_uri, prefix, owner_document) on this Element instance. |
get_computed_style() → "ComputedStyleDeclaration" | Return phase-2 cascade-resolved declarations for this element. |
insert_adjacent_html(position: str, html: str) | Insert parsed HTML markup relative to this element. |
insert_adjacent_text(position: str, text: str) | Insert a text node relative to this element. |
insert_adjacent_element(position: str, element: "Element | None") → "Element | None" | Insert element at position relative to this element. |
get_attribute(name: str) → str | None | Return the value of attribute name, or None if absent. |
set_attribute(name: str, value: str) | Set attribute name to value, creating it if not present. |
remove_attribute(name: str) | Remove attribute name. |
has_attribute(name: str) → bool | Return True if attribute name exists on this element. |
get_attribute_node(name: str) → "Attr | None" | Return the Attr object for attribute name, or None if absent. |
set_attribute_node(attr: "Attr") → "Attr | None" | Insert or replace attr in this element’s attribute set. |
remove_attribute_node(attr: "Attr") → "Attr" | Remove attr from this element’s attribute set and return it. |
get_attribute_node_ns(namespace_uri: str | None, local_name: str) → "Attr | None" | Return the Attr node matching namespace_uri and local_name, or None. |
set_attribute_node_ns(attr: "Attr") → "Attr | None" | Insert or replace a namespaced Attr node. |
remove_attribute_node_ns(namespace_uri: str | None, local_name: str) → "Attr" | Remove and return the Attr node matching namespace_uri and local_name. |
get_attribute_ns(namespace_uri: str | None, local_name: str) → str | None | Return the value of the namespaced attribute, or None if absent. |
set_attribute_ns(namespace_uri: str | None, qualified_name: str, value: str) | Set a namespaced attribute to value, creating it if not present. |
has_attribute_ns(namespace_uri: str | None, local_name: str) → bool | Return True if a namespaced attribute with the given local name exists. |
remove_attribute_ns(namespace_uri: str | None, local_name: str) | Remove the namespaced attribute. |
toggle_attribute(name: str, force: bool | None) → bool | Toggle attribute name and return its new presence state. |
get_attribute_names() → list[str] | Return the qualified names of all attributes in collection order. |
has_attributes() → bool | Return True when this element has one or more attributes. |
scroll_into_view(arg: bool | dict | None) | Scroll this element into view (no-op in server-side context). |
scroll(x_or_options: float | dict | None, y: float | None) | Scroll this element to coordinates (no-op in server-side context). |
scroll_into_view_if_needed(center_if_needed: bool) | Scroll this element into view if it is not already visible (no-op in headless mode). |
set_pointer_capture(pointer_id: int) | Designate this element as the capture target for the given pointer (no-op). |
release_pointer_capture(pointer_id: int) | Release pointer capture for the given pointer id (no-op). |
has_pointer_capture(pointer_id: int) → bool | Return whether this element has pointer capture for the given id. |
request_pointer_lock() | Request that the pointer be locked to this element (no-op). |
request_fullscreen(options: "dict | None") | Request that this element be displayed in fullscreen mode (no-op). |
check_visibility(options: "dict | None") → bool | Return whether this element is visible in the current rendering (always True). |
query_selector(selector: str) → Element | None | Return the first element in the subtree matching selector. |
query_selector_all(selector: str) → NodeList | Return a static NodeList of all elements matching selector. |
matches(selector: str) → bool | Return True if this element matches the CSS selector. |
webkit_matches_selector(selector: str) → bool | Browser-compat alias for :meth:matches. |
closest(selector: str) → "Element | None" | Return the nearest ancestor (inclusive) matching the CSS selector. |
get_elements_by_tag_name(qualified_name: str) → HTMLCollection | Return all descendant elements whose tag name matches qualified_name. |
get_elements_by_class_name(class_names: str) → HTMLCollection | Return all descendant elements that carry all of the given class tokens. |
filter_fn(el: "Element") → bool | Calls filter_fn(el) on this Element instance. |
remove() | Remove this element from its parent node. |
before() | Insert nodes immediately before this element in its parent. |
after() | Insert nodes immediately after this element in its parent. |
replace_with() | Replace this element with nodes in its parent. |
prepend() | Insert nodes before the first child of this element. |
append() | Append nodes as the last children of this element. |
replace_children() | Remove all children, then append nodes as new children. |
get_bounding_client_rect() → "DOMRect" | Return the bounding client rectangle (all-zero stub). |
get_client_rects() → "DOMRectList" | Return the client rectangle list (empty in server-side context). |
get_animations() → list[object] | Return active animations for this element (headless stub: always []). |
attach_shadow(init: "dict | None") | Raise NotSupportedError — shadow trees are not supported in headless mode. |
get_root_node(composed: bool) → "Node" | Return the root of the node’s tree. |
has_child_nodes() → bool | Return whether this node has at least one direct child node. |
lookup_namespace_uri(prefix: str | None) → str | None | Return the effective namespace URI for prefix in this node context. |
lookup_prefix(namespace_uri: str | None) → str | None | Return the effective prefix for namespace_uri in this node context. |
is_default_namespace(namespace_uri: str | None) → bool | Return whether namespace_uri equals this node context default namespace. |
is_supported(feature: str, version: str | None) → bool | Return legacy feature-probe compatibility status. |
get_feature(feature: str, version: str | None) → object | None | Return the legacy feature object for a probe, or None. |
set_user_data(key: str, data: object | None, handler: object | None) → object | None | Store or clear node-local user data and return the previous value. |
get_user_data(key: str) → object | None | Return node-local user data for key or None when absent. |
append_child(node: Node) → Node | Append node as the last child of this node. |
insert_before(node: Node, reference: Node | None) → Node | Insert node before reference in the child list. |
remove_child(node: Node) → Node | Remove node from the child list and return it. |
replace_child(new_child: Node, old_child: Node) → Node | Replace old_child with new_child. |
clone_node(deep: bool) → Node | Return a copy of this node. |
normalize() | Put this node and its entire subtree into normalized form. |
contains(other: Node | None) → bool | Return True if other is an inclusive descendant of this node. |
compare_document_position(other: "Node") → int | Return a bitmask describing the position of other relative to this node. |
is_equal_node(other: Node | None) → bool | Return True if other has the same structure as this node. |
is_same_node(other_node: Node | None) → bool | Return True when other_node is this node instance. |
add_event_listener(type: str, listener: Callable, capture: bool, once: bool) | Register listener for events of type. |
remove_event_listener(type: str, listener: Callable, capture: bool) | Deregister a previously-registered listener. |
dispatch_event(event: "Event") → bool | Dispatch event through the ancestor tree. |