Find all nodes on specific level #3138
-
Given an unordered list with multiple levels (lists within lists), how does one find only the list elements only on the first level? (Or at any given level.) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@forthrin I generally reach for XPath queries if I'm doing something more complicated than a tag name or an attribute. Try |
Beta Was this translation helpful? Give feedback.
-
Yep, that works. Just wondered if there was a CSS way to do it. Thanks! |
Beta Was this translation helpful? Give feedback.
@forthrin I generally reach for XPath queries if I'm doing something more complicated than a tag name or an attribute.
Try
doc.xpath("//li[not(ancestor::li)]")
and if that doesn't do what you want, please provide a sample input and your expected output?