Element

MainThread.Element represents an element. You can access or modify the element's properties in main thread scripts.

Instance Methods

Element.getAttribute()

Get the specified attribute value of the element. If the element does not have the specified attribute, returns undefined.

const value = element.getAttribute(attrName);

Element.getAttributeNames()

Get an array of the element's attribute names.

const nameArray = element.getAttributeNames();

Element.invoke()

Asynchronously invoke the element's UI method. Returns a Promise. When the UI method completes successfully, the Promise is resolved and returns the UI method's return value. If an exception occurs during the UI method call, the Promise is rejected and returns an Error object, with its message describing the error in detail.

const result = await element.invoke(methodName, params?);

Element.setAttribute()

Set the specified attribute of the element.

element.setAttribute(attrName, value);

Element.setStyleProperty()

Set the specified style of the element. The style name must be in kebab-case.

element.setStyleProperty(styleName, value);

Element.setStyleProperties()

Set the specified styles of the element using an object that can contain multiple "styleName: styleValue" records. The style names must be in kebab-case.

element.setStyleProperties(styleProperties);

Element.querySelector()

Find the first element within the element's child elements that matches the specified selector. Returns a MainThread.Element. If no matching element is found, returns null. For a list of supported selectors, see selector.

const element = element.querySelector(selector);

Element.querySelectorAll()

Find all elements within the element's child elements that match the specified selector. Returns an array of MainThread.Element. If no matching elements are found, returns an empty array. For a list of supported selectors, see selector.

const elementArray = element.querySelectorAll(selector);

Compatibility

Loading

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.