Selecting elements by name with wildcards

2019-08-31 22:16发布

问题:

Whats a good way to select elements by their name using wildcards?

The website has element names in the form of <a_1786439></a_1786439> which are likely auto-generated. This is doable by xpath, but is it doable using css selectors or jquery selectors which are faster?

This is clearly terrible-coding, but the website is not mine, and I'm writing a userscript for it.

回答1:

This doesn't exist in CSS3, as the spec's section on type selectors only includes names and wildcards, but no combinations of them.



回答2:

It's possible to create custom elements using the HTML DOM createElement method like this:

document.createElement('Funny_Element');

In the website code you are dealing with, they have created a custom element, or maybe extend the a element, but they didn't choose a significant name! a_1786439??? which is, I think, really bad.

Using CSS selectors or jQuery selectors depends essentially on what you want to do. Suppose you have to access children elements of a specific node, then jquery selectors would be more appropriate.

Hope it's useful!