Find next <p>" element above "<iframe>" element?

Find next <p>" element above "<iframe>" element?

Assume I want to find and hide the next "<p>" element above each "<iframe>" element.

Example:

  1. <p>
  2. sometext
  3. ...<p>
  4. somesubtext
  5. <iframe width="400" ....> ...</iframe>
  6. </p>
  7. other text ....
  8. <p>

When the target search filter is not an element but a text I could write:

$("p:contains('somesubtext')").eq(($("p:contains('somesubtext')").length) - 1).css("display", "none");

This is working fine.


However what if I want to search for an element <iframe> (possibly with an attribute filter).

then the following does NOT work:

$("p:contains('<iframe[width="400"]>')").eq(($("p:contains('<iframe[width="400"]>')").length) - 1).css("display", "none");


How else can I do this?

Peter