javascript - Add html to all content before a certain character -
okay, real shot in dark , not sure if phrased title correctly i'm trying follows:
i have html table looks this
<table> <tr> <td>type: tanker </td> <td>dwt: 8672.82 </td> </tr> <tr> <td>flag: gibraltar</td> <td>pumping capacity: 12 cargos pumps each 200m3/h </td> </tr> </table> what want wrap content "headers" in strong before ":" in dynamically table looks follows
<table> <tr> <td><strong>type:</strong> tanker </td> <td><strong>dwt:</strong> 8672.82 </td> </tr> <tr> <td><strong>flag:</strong> gibraltar</td> <td><strong>pumping capacity:</strong> 12 cargos pumps each 200m3/h </td> </tr> </table> i understand accomplish adding 2 more columns table , using css :first-child , nth-child selectors not way want go doing due size / layout constraints.
you can :
$('td').html(function(_,h){ homecoming h.replace(/([^:]+):/, '<strong>$1:</strong>') }); demonstration
javascript jquery html html5
No comments:
Post a Comment