Problem:
Querying an XML document with elements having specific strings embedded in their names can be challenging. Although CSS supports wildcards for attribute queries, the same functionality seems to be missing for element names.
Solution:
Unfortunately, there is no straightforward way to match wildcard element names using "querySelector()" or "querySelectorAll()". However, there are alternative approaches:
Attribute Matching: CSS provides wildcards for attribute values. To match elements with a particular string in their name, look for the presence of that string within any of their attributes using the following syntax:
Example:
To find all elements with the string "name" in their 'name' attribute, you could use:
const elementsWithName = document.querySelectorAll('[name*="name"]');
Note:
If you're seeking wildcard matching for the element tag name itself, there is currently no direct solution using "querySelector()" or "querySelectorAll()".
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3