I got a page and want to add a css class to every heading, which contains a specific word above it, inside the div "metadata". Here is an example:
<ul class="postlist">
<li><div class="postBox">
<h2><a href="http://sample.com"> Test Sample 1</a></h2>
<div class="metadata"><a href="LinkToCat" class="link" id="cat">Internal, Test</div>
</div></li>
<li><div class="postBox">
<h2><a href="http://sample.com"> Test Sample 2</a></h2>
<div class="metadata"><a href="LinkToCat" class="link" id="cat">Test</div>
</div></li>
</ul>
I tried with jquery like this:
if ($('div.postBox > div.metadata > a:contains("Internal")').length > 0)
$( "h2 a" ).addClass( "a-internal" );
This works - But the problem is, every heading element gets the class "a-internal", because the headings don't have unique IDs/names, right? Does somebody have an idea how I can nevertheless only add the class to the specific heading?
Thanks a lot!