Trying to wrap all words prior to the "," in each td cell. Note that words prior to "," in each cell will be different , so can not target a specific word per se
Existing html
<td class="name">
<a href="" title="" class="">lastName, firstName</a>
</td>
Desired outcome
<td class="name">
<a href="" title="" class=""><span>lastName</span>, firstName</a>
</td>
Attempts, all of which destroy the a href structure, I need to keep the a tag with class, title and href as is and just wrap the word/words prior to ","
$('td.name').each(function() {
$(this).html($(this).text().replace(/,.*$/, '<span class="after">$&</span>'));
});
$('td.name').html(function(i, v) {
return v.replace(/([^,]+)(,)/, '$1<span class="auther">$2</span>$3');
});
$('td.name').html(function (i, html) {
return html.replace(/(.*?,)/, '<span>$1</span>')
});