Is there a way to do a wildcard element name match using querySelector
or querySelectorAll
? I see support for wildcards in attribute queries but not for the elements themselves.
The XML document I'm trying to parse is basically a flat list of properties and I need to find elements that have certain strings in their names.
I realize the XML document is probably in need of a restructuring if I need this but that's just not going to happen.
Any solution except going back to using the apparently deprecated XPath (IE9 dropped it) is acceptable.
I was messing/musing on one-liners involving querySelector() & ended up here, & have a possible answer to the OP question using tag names & querySelector(), with credits to @JaredMcAteer for answering MY question, aka have RegEx-like matches with querySelector() in vanilla Javascript
Hoping the following will be useful & fit the OP's needs or everyone else's:
Then, we can, for example, get the src stuff, etc ...
+
I just wrote this short script; seems to work.
This works for me:
Show all names ending whith "057".
Set the tagName as an explicit attribute:
I needed this myself, for an XML Document, with Nested Tags ending in
_Sequence
. See JaredMcAteer answer for more details.I didn't say it would be pretty :) PS: I would recommend to use
tag_name
over tagName, so you do not run into interferences when reading 'computer generated', implicit DOM attributes.[id^='someId']
will match all ids starting withsomeId
.[id$='someId']
will match all ids ending withsomeId
.[id*='someId']
will match all ids containingsomeId
.If you're looking for the
name
attribute just substituteid
withname
.If you're talking about the tag name of the element I don't believe there is a way using
querySelector