2

I have multiple tables stacked inside a div container as below:-

<div id="myContent"  style="display: block;">
      <table id="myTable" cellspacing="0" cellpadding="0" >
        <tbody>
          <tr>
            <td style="padding-top: 10px;">
              <table>
                <tbody>
                  <tr>
                    <td align="left">
                      Health Care
                    </td>
                  </tr>
                  <tr>
                    <td align="left">
                      20 Wisconsin Ave</td>
                  </tr>
                  <tr>
                    <td align="left">
                      641.235.5900
                    </td>
                  </tr>
                  <tr>
                    <td align="left">
                      No website
                    </td>
                  </tr>
                </tbody>
              </table>
            </td>
            <td align="right">
              <img src="images/phone.png" class="imgHeader" >
            </td>
          </tr>
        </tbody>
      </table>
      <table id="myTable" cellspacing="0" cellpadding="0">
        <tbody>
          <tr>
            <td style="padding-top: 10px;">
              <table >
                <tbody>
                  <tr>
                    <td align="left">Housing</td>
                  </tr>
                  <tr>
                    <td align="left">
                      N/A</td>
                  </tr>
                  <tr>
                    <td align="left">
                      641.255.3884
                    </td>
                  </tr>
                  <tr>
                    <td align="left">
                      www.housingl.org
                    </td>
                  </tr>
                </tbody>
              </table>
            </td>
            <td align="right">
              <img src="images/phone.png" class="imgHeader" >
            </td>
          </tr>
        </tbody>
      </table>
      <table id="myTable" cellspacing="0" cellpadding="0" >
        <tbody>
          <tr>
            <td style="padding-top: 10px;">
              <table>
                <tbody>
                  <tr>
                    <td align="left">
                      Employment</td>
                  </tr>
                  <tr>
                    <td align="left">N/A</td>
                  </tr>
                  <tr>
                    <td align="left">
                      641.743.0500
                    </td>
                  </tr>
                  <tr>
                    <td align="left">
                      http://www.noexperience.org
                    </td>
                  </tr>
                </tbody>
              </table>
            </td>
            <td align="right">
              <img src="images/phone.png" class="imgHeader" >
            </td>
          </tr>
        </tbody>
      </table>
    </div>

I am trying to run a condition to find the TD with N/A and move those tables to the top. This is an additional question bult on the top of my previous question:

Finding the text "N/A" and hiding an image in table's next TD

I have a starting trouble with this code. Any support is appreciated.

4

2 回答 2

1
$('td').each(function(){
    if ($(this).text() === 'N/A') {
        $(this).parents('table').detach().prependTo('#myContent');
    }
});
于 2013-08-23T20:39:27.383 回答
1
$('td:contains(N/A)').closest('table').prependTo('#myContent');

jsFiddle 示例

于 2013-08-23T20:40:44.753 回答