find a element on a page by an custom attribute in javascript

To find an element on a page by a custom attribute using JavaScript, you can use the querySelectorAll method and pass in the attribute selector as a string. Here's an example:

index.tsx
const element = document.querySelectorAll('[data-custom-attribute="your-custom-value"]');
90 chars
2 lines

In this example, we are using the attribute selector [data-custom-attribute="your-custom-value"] to find any element with an attribute named data-custom-attribute with a value of your-custom-value. The querySelectorAll method returns a NodeList of all matching elements, which you can then manipulate or access as needed.

gistlibby LogSnag