You can use querySelectorAll
with a CSS selector to select elements that start with the same name in JavaScript. The CSS selector you can use is [attribute^=value]
, where attribute
is the attribute name you want to match against, and value
is the value you want to search for at the beginning of the attribute value.
Here's an example code that demonstrates how to use this selector to select all input elements with a name
attribute that starts with "user":
index.tsx69 chars2 lines
This will return a NodeList containing all input elements with name
attributes that start with "user". You can then loop through this list to access each input element or do whatever other operation you need to do with them.
gistlibby LogSnag