Hi I’m trying to add a class to to the project based on the first tag the project has.
So far this works:
$('.project_footer').ready(function() {
$('.project').addClass( $('.tag a').text());
});
However is finding every tag in every project_footer in the document and applying it as a class to every project. I just want the first one and apply it to that individual project.
Any advice?
EDIT:
<div class="project blue">
<p>content content content</p>
<div class="project_footer">
<span class="tags"><a href="/projects/allblue">Blue</a></span>
</div>
</div>
You need to use both
parentandeachjQuery functions, like this:I just created a jsFiddle to show it working 🙂 http://jsfiddle.net/MA9CV/1
EDIT
If you have more than one tag, change
find('.tags a')tofind('.tags:first-child a')like shown in this jsFiddle http://jsfiddle.net/MA9CV/2/