I wonder is this the most elegant and efficient way to do this?
I have several tag lists, and through CSS I want the tags to be displayed inline (display: inline) and separated by a comma. The task I am experiencing is to add commas to all but the last element of the list in each ul.tagList:
<ul class="outerList"> <li> <div class="innerContainer"> <ul class="tagList"> <li>Tag A</li> <li>Tag B</li> <li>Tag C</li> </ul> </div> </li> <li> <div class="innerContainer"> <ul class="tagList"> <li>Tag D</li> <li>Tag E</li> <li>Tag F</li> </ul> </div> </li> </ul>
To add commas to all the elements of the ul.tagList list, but the last one I use:
$('ul.tagList').children(':not(:last-child)').append(',');
and it gives:
Tag A, Tag B, Tag C
Tag D, Tag E, Tag F
Is this the best way to do this?
Also why: not (: last-child) works, but not: not (: last) in this context?
Thank you very much for your help + explanation.
Prembo
source share