query select all with "cb" in name in javascript

You can use the querySelectorAll() method to select all elements with cb in their name attribute using a CSS attribute selector.

index.tsx
const elements = document.querySelectorAll('[name*="cb"]');
60 chars
2 lines

This will select all elements that have the attribute name containing the substring cb. The *= operator is used to match substring.

You can then loop through the elements NodeList and do whatever you need with them.

index.tsx
elements.forEach(element => {
  // do something with each element
});
70 chars
4 lines

gistlibby LogSnag