I want to match all elements in an HTML Dom tree which have any attribute with the value "foo". It should either be a CSS or a XPath selector.
My naive approach would be something like this as css selector:
*[*='foo']
How is the correct syntax?
The [attribute|="value"] selector is used to select elements with the specified attribute, whose value can be exactly the specified value, or the specified value followed by a hyphen (-). Note: The value has to be a whole word, either alone, like class="top", or followed by a hyphen( - ), like class="top-text".
Advantages and disadvantages of CSS SelectorsPerformance is the same or faster compared to XPath. Easier to learn than XPath, easier to use. CSS Selector only allows unidirectional flow. Using a CSS Selector, we can only traverse from parent to child but not from the child to parent, which is possible with XPath.
XPath Tutorial from basic to advance level. This attribute can be easily retrieved and checked by using the @attribute-name of the element. @name − get the value of attribute "name". <td><xsl:value-of select = "@rollno"/></td> Attribute can be used to compared using operators.
The [attribute=value] selector is used to select elements with the specified attribute and value.
CSS does not define an attribute selector that takes a wildcard as its name.
XPath, however, does. The following expression should work:
//*[@*="foo"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With