JQuery add the first part of the div, then add the last part of the seperatley div

I am trying to wrap the following prices and text in one div.

Here is what I have:

<table cellspacing="0" cellpadding="0" border="0" class="thePrices">
  <tbody>
    <tr>
      <td>
        <font class="text colors_text">
          <b>MSRP: <span class="priceis">$90.00</span></b>
        </font><br>
        <b><font class="pricecolor colors_productprice">
                     <font class="text colors_text"><b>Burkett Price:</b></font>
        <span class="priceis">$289<sup>.99</sup></span>
        </font>
        </b><br>
        <a href="a link">A link goes here</a>
        <table>A TABLE WITH STUFF GOES HERE</table>
      </td>
    </tr>
  </tbody>
</table>
Run codeHide result

Here is what I am trying to get:

<table cellspacing="0" cellpadding="0" border="0" class="thePrices">
  <tbody>
    <tr>
      <td>
        **
        <div class="pricebox">**
          <font class="text colors_text">
            <b>MSRP: <span class="priceis">$90.00</span></b>
          </font><br>
          <b><font class="pricecolor colors_productprice">
                         <font class="text colors_text"><b>Burkett Price:</b></font>
          <span class="priceis">$289<sup>.99</sup></span>
          </font>
          </b><br> **
        </div>**
        <a href="a link">A link goes here</a>
        <table>A TABLE WITH STUFF GOES HERE</table>
      </td>
    </tr>
  </tbody>
</table>
Run codeHide result

This does not work, but you understand what I'm doing wrong:

$(document).ready(function () {
$('.thePrices').find('td').find('font:first').before('<div class="pricebox">');
$('.thePrices').find('.colors_productprice').find('b').after('</div>');
});

Maybe I should use SLICE?

+5
source share
2 answers

I think you want updated, use to enable.wrapAll()
.andSelf()<font/>

$('.thePrices').find('td').children().first().nextUntil('a').andSelf().wrapAll('<div class="pricebox"></div>');

Jsfiddle example

+5
source
$('.thePrices>tbody>tr>td').children().slice(0,3).wrapAll('<div class="pricebox"></div>');

slice(), 3 , , <br> - br , a 3 4

0

All Articles