我在一个div容器中有多个表,如下所示:-

<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>

我试着运行一个条件,找到不适用的TD,并将这些表移到顶部。这是我上一个问题之外的另一个问题:
Finding the text "N/A" and hiding an image in table's next TD
我在这段代码中遇到了启动问题。如有任何支持,我们将不胜感激。

最佳答案

$('td:contains(N/A)').closest('table').prependTo('#myContent');

jsFiddle example

关于javascript - 如何基于带有JQuery的条件将表移动到DIV容器的顶部?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18411373/

10-12 03:19