selector with role button in javascript

To select an element with a role of button in JavaScript, you can use the querySelector method with the [role=button] attribute selector.

index.tsx
const buttonElement = document.querySelector('[role=button]');
63 chars
2 lines

This will select the first element in the document with a role attribute set to "button".

Alternatively, you can use querySelectorAll to select all elements with this role:

index.tsx
const buttonElements = document.querySelectorAll('[role=button]');
67 chars
2 lines

This will return a NodeList of elements that have the specified role.

gistlibby LogSnag