Module: actions
Table of contents
Functions
Functions
performElementAction
▸ performElementAction(captainId
, action
): void
Executes a specified action on an HTML element identified by its data-captainid
attribute.
This function aims to abstract the common pattern of querying an element by its data-captainid
and then performing some action on that element. It uses CSS.escape
to ensure that the captainId
is safely used in a query selector, protecting against CSS injection vulnerabilities and syntax errors
due to special characters.
Parameters
Name | Type | Description |
---|---|---|
captainId | string | The unique identifier associated with the element's data-captainid attribute. |
action | (element : HTMLElement ) => void | A callback function that performs an operation on the found element. The action is only executed if the element is successfully queried from the DOM. |
Returns
void
Example
// Focuses an element with `data-captainid="username-input"`
performElementAction("username-input", (el) => el.focus());
Example
// Clicks a button with `data-captainid="submit-button"`
performElementAction("submit-button", (el) => el.click());
Throws
Logs an error to the console if the element cannot be found or if the action throws an error.
Defined in
actions.js:23