Shorter command for search innermost element which contains certain string?
- <div class="one">....
- ....
- <div class="two">....
- ...
- <div class="three">.....
- <p>
- <strong>
- blah foobar other text
- </strong>
- ....
- </p>
- </div>
- ....</div>
- ....</div>
I am searching for a shorter (!) way to delete (resp.refer to) the innermost, nested <div> element which contains directly or indirectly in (sub)child elements the string "foobar".
It the sample above only <div> element with class="three" should be removed.
Currently I am using the following command:
$("div:contains('foobar')").eq(($("div:contains('foobar')").length) - 1).remove();
It works. However it looks plump and artificial.
I can imagine that there is a smarter,shorter way in jQuery.
The command should be applied to all occurencies in a web page.
So if "foobar" appears somewhere else (below) the removal should be applied as well.
Peter