I am looking to choose one or more elements that are NOT children of a specific element.
<html>
<body>
<div>
<p>
<b>
<i> don't pick me </i>
</b>
</p>
</div>
<div>
<i>don't pick me either </i>
</div>
<i> select me </i>
<b>
<i> select me as well </i>
</b>
</body>
</html>
In the illustration above, my goal is to pick all 'i' elements that are not contained within div elements. It's not straightforward using ('div i') in :not() function.
How can I pick all i elements outside of div elements? The common suggestion is to use jQuery, such as:
nondiv_i = all_i.not(all_div.find("i"))
I cannot utilize jQuery, but jqLite - which does not have a not()-function. A jqLite solution is appreciated too! Is there a way to achieve this without repetitive iterations and comparisons?
Edit: To clarify, I want no div ancestors for my i-elements, not just direct div parents.
A related XPath would be like this:
//i[not(ancestor::div)]