How to change content of a td tag to separate p tags by jQuery

  Kiến thức lập trình

Sorry for my newbies question about jQuery, because I don’t know how to do with it ???? and I’ve been faced with a problem that only will solve with jQuery. Thank you in advance.

I want to change the p tag content inside td tag to separate p tags, if the content has comma (separate by ‘,’).

Current HTML:

<table class="shop_attributes">
  <tbody>
    <tr>
      <th class="label">Ports</th>
      <td class="value">
        <p>3 ports</p>
      </td>
    </tr>
    <tr>
      <th class="label">Types</th>
      <td class="value">
        <p>1 VGA, 1 HDMI, 1 LAN</p>
      </td>
    </tr>
  </tbody>
</table>

After update by jQuery:

<table class="shop_attributes">
  <tbody>
    <tr>
      <th class="label">Ports</th>
      <td class="value">
        <p>3 ports</p>
      </td>
    </tr>
    <tr>
      <th class="label">Types</th>
      <td class="value">
        <p>1 VGA</p>
        <p>1 HDMI</p>
        <p>1 LAN</p>
      </td>
    </tr>
  </tbody>
</table>

LEAVE A COMMENT