Nourdine Alouane
Nourdine Alouane

Reputation: 814

Not select Child class element (Jsoup)

Is there a way in jsoup to select all <p> tag elements except the one that contains <iframe> tag:

<p>Text</p>
<p>Text</p>
<p><iframe scr='..'></iframe></p>
...
<p>Text</p>

I have tried document.select("p:not(iframe)")

and

document.select("p:not(p iframe)")

but with no success, from this link it says that working against the cascade by selecting an ancestor based on a descendant is impossible in CSS, but I saw some jquery solutions, so I'm wondering if there is solutions in jsoup to solve this problem

EDIT:

I found this solution, but it needs some additional java coding, I'm looking for a solution with only css selector that will come from a database

Upvotes: 1

Views: 945

Answers (1)

TDG
TDG

Reputation: 6151

Use this - p:not(:has(iframe)).
You can see a working example here.

Upvotes: 3

Related Questions