Selecting elements by name with wildcards

点点圈 提交于 2019-12-13 03:47:37

问题


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!



来源:https://stackoverflow.com/questions/25867922/selecting-elements-by-name-with-wildcards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!