Class dom_element

Web process Lua interface to the DOM
This module is only available from web process Lua states.

The dom_element class allows interaction with elements on any web page.

Methods

element:query (selector)

Find all sub-elements which match a given CSS selector.

Parameters

  • selector
    Type: string
    A CSS selector.

Return Values

  • {dom_element}
    All sub-elements which match the selector.

element:append (child)

Append a new child element to the end of the element's children.

Parameters

  • child
    Type: dom_element
    The new child element.

element:remove ()

Remove the element from its parent element.

element:click ()

Simulate a mouse click on the element.

element:focus ()

Focus the element.

element:submit ()

If the element is a form element, submit the form.

element:add_event_listener (type, capture, callback)

Add an event listener to this element. The callback will be called with a single table argument, which will have a target field containing the event source element. If the event is a mouse event, it will also have a button field, containing the mouse button number.

Parameters

  • type
    Type: string
    The type of event to listen for.
  • capture
    Type: boolean
    Whether the event should be captured.
  • callback
    Type: function
    The callback function.

Properties

element.inner_html

Type: string
Read-write
The inner HTML of the element.

element.tag_name

Type: string
Read-only
The tag name of the element.

element.text_content

Type: string
Read-only
The text content of the element.

element.child_count

Type: integer
Read-only
The number of child elements this element has.

element.src

Type: string
Read-only
The "src" attribute of the element.

element.href

Type: string
Read-only
The "href" attribute of the element.

element.value

Type: string
Read-write
The "value" attribute of the element.

element.checked

Type: boolean
Read-write
Whether this element is checked.

element.type

Type: string
Read-only
The "type" attribute of the element.

element.parent

Type: dom_element
Read-only
The parent element of this element.

element.first_child

Type: dom_element
Read-only
The first child element of this element.

element.last_child

Type: dom_element
Read-only
The last child element of this element.

element.prev_sibling

Type: dom_element
Read-only
The previous sibling element of this element.

element.next_sibling

Type: dom_element
Read-only
The next sibling element of this element.

element.rect

Type: table
Read-only
The position of the element within the containing DOM document. It has four keys: top, left, width, and height.

element.style

Type: table
Read-only
Table of computed styles. Index should be the name of a CSS property value.

element.attr

Type: table
Read-write
The attributes of the DOM element and their values, as key/value pairs. All keys and values must be strings. Iteration with next() or pairs() does not work.

element.document

Type: dom_document
Read-only
The DOM document that this element is within. If this element is within a subframe, the document returned will be the DOM document for that subframe, not the top-level document.

element.owner_document

Type: dom_document
Read-only
The DOM document that is the top-level document object for this element. one document and added to another.

Signals

"destroy"

Emitted when the element is destroyed.

Attribution

Copyright