1

The HTML class attribute is a whitespace-separated list. E.g.,

<div class="aaa bbb ccc">
    ...
</div>

Is there a simple XPath expression that selects all div-s with class aaa (i.e. where the class list contains aaa). I have found a complicated solution (source):

//div[contains(concat(" ", normalize-space(@class), " "), " aaa ")]

Is there a simple solution?

The solution has to work with all major up-to-date browsers, inside Document.evaluate(), which is XPath 1.0, but ultimately I am curious about any solutions in later XPath versions too.

2
  • If you don't care about anything but aaa, then simply //div[contains(@class,"aaa")] would do. Commented Jun 21 at 13:44
  • 2
    There is no simpler XPath 1.0 expression that’s equally reliable.The expression you already have is the recommended approach for that XPath version Commented Jun 21 at 14:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.