I have a few actor names separated by commas, and I am trying to get each name in that list and plug it into a dynamically created li of its own under a ul while capitalizing the first letter only and trimming commas/spaces (the only space that should not get trimmed is between “john lock” since there is no comma there between the name) like this:
var cast = ('jack, kate ,sawyer , john lock ,, hurley')
<ul id="cast-members">
<li>Jack</li>
<li>Kate</li>
<li>Sawyer</li>
<li>John Lock</li>
<li>Hurley</li>
</ul>
Any idea how to get this accomplished with jQuery?
This should do it
demo at http://jsfiddle.net/gaby/gvb6n/