2

I have multiple DIVs being used to list items like so:

<div class="project-item Video">
    <p>Test</p>
</div>

Each DIV has a set of categories added to it (for example, Video).

I want to automatically create list items from the classes, but leave out .project-item.

Problems I'm facing are making sure the categories don't repeat. There will be multiple DIVs listed. e.g:

<div class="project-item Video">
    <p>Test</p>
</div>
<div class="project-item Photography">
    <p>Test</p>
</div>
<div class="project-item Video Photography">
    <p>Test</p>
</div>

There is a UL above the DIV's with the following markup:

<ul id="filters" class="option-set clearfix" data-option-key="filter">
    <li><a href="#filter" data-option-value="*" class="selected">Show all</a></li>
</ul>

Underneath the 'Show All' LI I want to then list each category, for example:

<ul id="filters" class="option-set clearfix" data-option-key="filter">
    <li><a href="#filter" data-option-value="*" class="selected">Show all</a></li>
    <li><a href="#filter" data-option-value="Video">Video</a></li>
</ul>

Here is a jsFiddle that shows the example HTML markup without the needed lists: http://jsfiddle.net/GaExx/1/

Justin
  • 329
  • 2
  • 9
  • 19
  • What have you tried so far? It should not be difficult to [get all classes of the `.project-item` elements](http://stackoverflow.com/questions/9279368/how-to-get-all-css-classes-of-an-element). Then you have to make sure to get the [unique elements of the array](http://stackoverflow.com/questions/1890203/unique-for-arrays-in-javascript), iterate over them and create the list entries. What particularly are you having problems with? – Felix Kling Apr 30 '12 at 08:59
  • (what I want to say is that all the pieces are there, you just have to put them together) – Felix Kling Apr 30 '12 at 09:06
  • My biggest issue so far has been rendering unique
  • items from the classes I've pulled, as well as not including "project-item" as one of those items. The best I got was listing it, then removing it - which is lengthy and I'm positive there is cleaner code. Everything I write seems to be way to bulky without the desired effect! I'll have a look through those links :)
  • – Justin Apr 30 '12 at 09:14