I have a long list of names, and I want to add an anchor to the first element in a given class.
<ul id="the_names">
<li class="names letter-A">Ames, Aldrich</li>
<li class="names letter-A">Andrews, Richard</li>
<li class="names letter-B">Barber, Deborah</li>
<li class="names letter-B">Brown, Bobby</li>
<li class="names letter-C">Clark, Richard</li>
<li class="names letter-C">Coates, Charles</li>
<li class="names letter-D">Day, Doris</li>
<li class="names letter-D">Dole, Elizabeth</li>
</ul>
I've tried several methods using jQuery to get all the class names used by the li's, but all are coming up short, usually just returning names letter-A
.
What I want to end up with is an anchor tag at the FIRST occurrence of the class letter-A
, same at letter-B, letter-C, etc.:
<ul id="the_names">
<li class="names letter-A"><a name="letter-A">Ames, Aldrich</a></li>
<li class="names letter-A">Andrews, Richard</li>
<li class="names letter-B"><a name="letter-A">Barber, Deborah</a></li>
<li class="names letter-B">Brown, Bobby</li>
<li class="names letter-C"><a name="letter-A">Clark, Richard</a></li>
<li class="names letter-C">Coates, Charles</li>
<li class="names letter-D"><a name="letter-A">Day, Doris</a></li>
<li class="names letter-D">Dole, Elizabeth</li>
</ul>
Thanks for the help.