Quantcast
Channel: User Ja͢ck - Stack Overflow
Viewing all articles
Browse latest Browse all 44

Answer by Ja͢ck for xpath to exclude elements that have a class

$
0
0

You can use negation:

//*[@id="mydiv" and @class!="exclass"]

If the class attribute may not exist on all nodes, you need this:

//*[@id="mydiv" and (not(@class) or @class!="exclass")]

The last (somewhat) odd logic can be turned into what Michael proposed:

//*[@id="mydiv" and not(@class="exclass")]

Though, personally, the fact that XPath cannot make comparisons if the attribute is missing feels a bit like a shortcoming.


Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>